0
我正在使用畢加索在我的Android應用程序中設置gridview。我想要做的是基本上在gridview中按下圖像並轉到詳細視圖。Android Picasso GridView - 將URL數據存儲在Integer數組中?
的數據字符串數組被填充,像這樣:
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
這些網址將被放在一個字符串的ArrayList:
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;
}
}
問題是,當我想該項目的ID,它都存儲在字符串中。這裏是我的詳細信息查看活動的樣子:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.full_image);
// get intent data
Intent i = getIntent();
// Selected image id
int position = i.getExtras().getInt("id");
ImageAdapter ia = new ImageAdapter(this);
ImageView iv = (ImageView) findViewById(R.id.full_image_view);
iv.setImageResource(ia.getItemId(position));
}
的position
是從我的主要活動,它是整數。當我想把getItemId,setImageResource
引發此錯誤:
The method setImageResource(int) in the type ImageView is not applicable for the arguments (long)
你們是否有任何想法如何解決這一問題?
編輯:新增ImageAdapter類代碼
嘗試'iv.setImageResource(網址[位置]);'也發表您的'ImageAdapter' – VenomVendor
u能顯示你的ImageAdapter類代碼? –
在問題中添加 – AimanB