android - How to show the selected image from list view in another activity .Getting images from URLs -
image adapter class public class imagelistadapter extends arrayadapter { private context context; private layoutinflater inflater; private string[] imageurls; public imagelistadapter(context context, string[] imageurls) { super(context, r.layout.listview_item_image, imageurls); this.context = context; this.imageurls = imageurls; inflater = layoutinflater.from(context); } @override public view getview(int position, view convertview, viewgroup parent) { if (null == convertview) { convertview = inflater.inflate(r.layout.listview_item_image, parent, false); } picasso .with(context) .load(imageurls[position]) .fit() // explain later .into((imageview) convertview); return convertview;
main class
public class usageexampleadapterextends appcompatactivity { public static string[] eatfoodyimages = { "http://i.imgur.com/76jfv9b.jpg", "http://i.imgur.com/fux7eib.jpg", "http://i.imgur.com/syelajx.jpg", "http://i.imgur.com/cozbnru.jpg", "http://i.imgur.com/z3qjila.jpg", }; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_usage_example_adapter); listview listview = (listview) findviewbyid(r.id.listview); // listview.setadapter(adapter); listview.setadapter(new imagelistadapter(usageexampleadapter.this, eatfoodyimages)); listview.setonitemclicklistener(new adapterview.onitemclicklistener() { public void onitemclick(adapterview<?> parent, view view, int position, long id) { intent intent = new intent(usageexampleadapter.this, singleitemview.class); intent.putextra("position", position); startactivity(intent); } }); } }
singleitemview class
public class singleitemview extends activity { @override protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); setcontentview(r.layout.singleitemview); imageview imageview = (imageview) findviewbyid(r.id.imageview); int position = getintent().getintextra("position", -1); if(position !=1){ picasso.with(this) .load(usageexampleadapter.eatfoodyimages[position]) .into(imageview); } }
i getting images url , using picasso showing in listview.on selecting image listview want display in activity.while doing above thing getting blank white activity.
replace code
if(position !=1){ picasso.with(this) .load(usageexampleadapter.eatfoodyimages[position]) .into(imageview); }
with
if(position !=1){ picasso.with(this) .load(main.eatfoodyimages[position]) .into(imageview); }
Comments
Post a Comment