Android毕加索GridView-以整数数组存储URL数据?
我正在使用毕加索在我的Android应用程序中设置gridview。我想做的基本上是在gridview中按一个图像,然后转到细节视图 数据填充在字符串数组中,如下所示:Android毕加索GridView-以整数数组存储URL数据?,android,picasso,Android,Picasso,我正在使用毕加索在我的Android应用程序中设置gridview。我想做的基本上是在gridview中按一个图像,然后转到细节视图 数据填充在字符串数组中,如下所示: static final String[] URLS = { "http://i.imgur.com/file1.jpg", "http://i.imgur.com/file2.jpg", "http://i.imgur.com/file3.jpg", "http://i.imgur.com/file4.jpg" }
static final String[] URLS = {
"http://i.imgur.com/file1.jpg", "http://i.imgur.com/file2.jpg",
"http://i.imgur.com/file3.jpg", "http://i.imgur.com/file4.jpg"
};
在ImageAdapter
中,这些URL将放在字符串数组列表中:
public class ImageAdapter extends BaseAdapter {
private final Context context;
private final List<String> urls = new ArrayList<String>();
public ImageAdapter(Context context) {
this.context = context;
// Ensure we get a different ordering of images on each run.
Collections.addAll(urls, Data.URLS);
//Collections.shuffle(urls);
// Triple up the list.
ArrayList<String> copy = new ArrayList<String>(urls);
urls.addAll(copy);
}
@Override public View getView(int position, View convertView, ViewGroup parent) {
SquaredImageView view = (SquaredImageView) convertView;
if (view == null) {
view = new SquaredImageView(context);
view.setScaleType(CENTER_CROP);
}
// Get the image URL for the current position.
String url = getItem(position);
// Trigger the download of the URL asynchronously into the image view.
Picasso.with(context) //
.load(url) //
.placeholder(R.drawable.placeholder) //
.error(R.drawable.error) //
.fit()
.centerCrop()//
.into(view);
return view;
}
@Override public int getCount() {
return urls.size();
}
@Override public String getItem(int position) {
return urls.get(position);
}
@Override public long getItemId(int position) {
return position;
}
}
位置
来自我的主要活动,它是整数。当我想放置getItemId时,setImageResource
抛出以下错误:
类型ImageView中的方法setImageResource(int)不可用
适用于参数(长)
你们知道怎么解决这个问题吗
编辑:添加了ImageAdapter类代码您仍然需要在细节视图中调用Picasso,并从适配器传递URL,而不是ID
Picasso.with(context) //
.load(ia.getItem(position)) //
.placeholder(R.drawable.placeholder) //
.error(R.drawable.error) //
.fit()
.centerCrop()//
.into(iv);
尝试
iv.setImageResource(URL[position])
同时发布你的ImageAdapter
你能显示你的ImageAdapter类代码吗?问题中添加
Picasso.with(context) //
.load(ia.getItem(position)) //
.placeholder(R.drawable.placeholder) //
.error(R.drawable.error) //
.fit()
.centerCrop()//
.into(iv);