Gridview - Click Gridview Item To Show Image In Imageview
I follow this toturial Android Lazy Loading images and text in listview from http json data and now i change listview to gridview. My question is I want to click gridview item and
Solution 1:
In gridview onClickListener
get data of clicked item
gridView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int positon,
long id) {
HashMap<String, Object> hm = gridView.getAdapter().getPosition(positon);
String imgPath = (String) hm.get("flag"); //get downloaded image path
Intent i = new Intent(yourActivityContext, NewActivityToDisplayImage.class); //start new Intent to another Activity.
i.putExtra("ClickedImagePath", imgPath ); //put image link in intent.
startActivity(i);
}
});
In NewActivityToDisplayImage
get image path and set to imageview.
public class NewActivityToDisplayImage extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout);
String imagePath = getIntent().getStringExtra("ClickedImagePath"); //get image path from post activity
if (imagePath != null && !imagePath.isEmpty) {
File imgFile = new File(imagePath);
if (imgFile.exists()) {
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
ImageView myImage = (ImageView) findViewById(R.id.imageviewTest);
myImage.setImageBitmap(myBitmap);
}
}
}}
Post a Comment for "Gridview - Click Gridview Item To Show Image In Imageview"