我在我的android應用程序中有網格視圖,我希望當我點擊網格視圖中的一個圖像時,它會在全視圖中顯示該圖像。點擊監聽網格視圖時顯示圖像ANdroid
當前它顯示圖片點擊它時的位置。
這裏是代碼
GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(new ImageAdapter(this));
gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
Toast.makeText(ViewActivity.this, "" + position,
Toast.LENGTH_SHORT).show();
}
});
這裏是ImageAdapter
public class ImageAdapter extends BaseAdapter {
private Context mContext;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) {
// if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
} else {
imageView = (ImageView) convertView;
}
Picasso.with(mContext).load(mThumbIds[position]).into(imageView);
//imageView.setImageResource(Integer.parseInt(mThumbIds[position]));
return imageView;
}
public String[] mThumbIds = new String[]{
"http://192.168.1.4/comic_app/index.php?id=1",
"http://192.168.1.4/comic_app/index.php?id=67",
"http://192.168.1.4/comic_app/index.php?id=4",
"http://192.168.1.4/comic_app/index.php?id=89",
"http://192.168.1.4/comic_app/index.php?id=98",
"http://192.168.1.4/comic_app/index.php?id=23",
"http://192.168.1.4/comic_app/index.php?id=45",
};
}
如何顯示在該圖像的點擊圖片。
在此先感謝。
http://android-er.blogspot.com/2012/12/implement-onitemclicklistener-for.html - 本教程將幫助你。 –