Android 如何使用毕加索库设置imageview?

Android 如何使用毕加索库设置imageview?,android,picasso,Android,Picasso,我有我的GridViewAdapter,我想用我从毕加索下载的东西设置一个imageview。图像已加载,但未显示在GridView中,只有当我单击图像时,才会像单击图像时一样全屏显示图像。。每一个答案都会被解释清楚。谢谢 private static LayoutInflater inflater = null; public GridViewAdapter(Activity a, String[] fpath, String[] fname) { activity = a;

我有我的GridViewAdapter,我想用我从毕加索下载的东西设置一个imageview。图像已加载,但未显示在GridView中,只有当我单击图像时,才会像单击图像时一样全屏显示图像。。每一个答案都会被解释清楚。谢谢

private static LayoutInflater inflater = null;

public GridViewAdapter(Activity a, String[] fpath, String[] fname) {
    activity = a;
    filepath = fpath;
    filename = fname;
    inflater = (LayoutInflater) activity
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

}

public int getCount() {
    return filepath.length;

}

public Object getItem(int position) {
    return position;
}

public long getItemId(int position) {
    return position;
}


public View getView(int position, View convertView, ViewGroup parent) {
    View vi = convertView;
    if (convertView == null)
        vi = inflater.inflate(R.layout.gridview_item, null);
    // Locate the TextView in gridview_item.xml
    TextView text = (TextView) vi.findViewById(R.id.text);
    // Locate the ImageView in gridview_item.xml
     image = (ImageView) vi.findViewById(R.id.grid_image);

    // Set file name to the TextView followed by the position

    Picasso.with(parent.getContext()).load(filepath[position]).placeholder(R.drawable.rtrt).fit().centerCrop().into(image);

    // Decode the filepath with BitmapFactory followed by the position


    // Set the decoded bitmap into ImageView
  //  image.setImageBitmap(bmp);
    return vi;
}

}

在此处使用
活动
上下文

 Picasso.with(activity).load(filepath[position]).placeholder(R.drawable.rtrt).fit().centerCrop().into(image);
在getView()方法中

注:

1.如果图像的路径是本地的,请确保正在传递文件。 2.从调用适配器的活动中传递上下文,如
SampleActivity。此

并尝试在适配器构造函数中将活动对象更改为上下文对象


有关如何从服务器加载包含图像的网格视图的更多详细信息,请检查

如果图像路径是本地的,则必须使用文件

File file = new File(filepath[position]);
 Picasso.with(activity).load(file).placeholder(R.drawable.rtrt).fit().centerCrop().into(image);

毕加索.with(activity).load(filepath[position]).placeholder(R.drawable.rtrt).fit().centerCrop().into(图像)@乔治霍马斯,你能帮我做一个视图持有者模式吗,因为我是安卓系统的新手。谢谢,请共享设置adapterWrite代码的代码,您在活动中创建GridViewAdapter的代码。然后尝试使用activity.getApplicationContext()使用activity.getApplicationContext()在我写了这个之后,它说:非静态方法getApplicationContext()不能从静态上下文引用…非常感谢@George Thomas!
File file = new File(filepath[position]);
 Picasso.with(activity).load(file).placeholder(R.drawable.rtrt).fit().centerCrop().into(image);