android - Intent not sending right data on next activity from ListView -
i made 1 listview imageview , textview. when click on image using intent pass image uri , text next activity.now first four cells of listview getting right data on next activity.but when scroll listview , click on cell of listview wrong data sent.so if knows solution please post it... thanks in advance
here code of adapter class..
public class adapter extends baseadapter { private static final string tag = "adapter"; private activity mactivity; public arraylist<data> mobjects; // /private final context context; context context; static class viewholder { static imageview icon; textview title; textview name; textview review; downloadimagetask mtask; string ab[]; // downloadimagetask1 mtask1; // imageview photo; } public adapter(activity activity, context context, arraylist<data> mobjects) { this.mactivity = (activity) activity; this.context = context; this.mobjects = mobjects; } public void setobjects(arraylist<data> mobjects) { this.mobjects = mobjects; } @override public view getview(final int position, view convertview, viewgroup parent) { final data item = mobjects.get(position); view rowview = convertview; if (rowview == null) { layoutinflater inflater = mactivity.getlayoutinflater(); rowview = inflater.inflate(r.layout.item, parent, false); viewholder viewholder = new viewholder(); viewholder.icon = (imageview) rowview.findviewbyid(r.id.image); // viewholder.photo = (imageview) rowview.findviewbyid(r.id.photo); viewholder.title = (textview) rowview.findviewbyid(r.id.title); viewholder.name = (textview) rowview.findviewbyid(r.id.name); viewholder.review = (textview) rowview.findviewbyid(r.id.status); rowview.settag(viewholder); } viewholder holder = (viewholder) rowview.gettag(); holder.title.settext(item.getmtitle()); holder.name.settext(item.getmconcatinate()); holder.review.settext(item.getmreview()); holder.icon.setbackgroundresource(r.drawable.ic_ab); // holder.photo.setbackgroundresource(0); holder.mtask = new downloadimagetask(item.getmimageurl(), holder.icon); if (!holder.mtask.iscancelled()) { holder.mtask.execute(); } viewholder.icon.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { log.d("parsing json data", "before user try122222"); // perform //object tag= v.gettag(); log.d("parsing json data","abc"); string title = item.getmconcatinate(); string picture=item.getmimageurl(); intent intent = new intent(v.getcontext(), largeview.class); log.d("parsing json data", "before user try444444"); intent.putextra("data", title); log.d("parsing json data", "before user try555555"); intent.putextra("image3",picture); log.d("parsing json data", "before user try66666666"); v.getcontext().startactivity(intent); log.d("parsing json data", "before user try7777"); } }); // holder.mtask1 = new downloadimagetask1(item.getmimageurl1(), // holder.photo); // if (!holder.mtask1.iscancelled()) { // holder.mtask1.execute(); // } return rowview; } @override public int getcount() { return (this.mobjects.size()); } @override public object getitem(int position) { return (this.mobjects.get(position)); } @override public long getitemid(int position) { return (position); } public abslistview.recyclerlistener mrecyclerlistener = new recyclerlistener() { public void onmovedtoscrapheap(view view) { viewholder viewholder = (viewholder) view.gettag(); downloadimagetask imagetask = viewholder.mtask; // downloadimagetask1 imagetask1 = viewholder.mtask1; if (imagetask != null) { imagetask.cancel(true); } // if (imagetask1 != null) { // // imagetask1.cancel(true); // } } };
}
code next activity...
public class largeview extends activity { //imageview image4; //bitmap bm1; //string image_url; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_large_view); textview text=(textview)findviewbyid(r.id.textview1); imageview image4=(imageview)findviewbyid(r.id.largeimage); //button button=(button)findviewbyid(r.id.back99); intent intent2 = getintent(); log.d("parsing json data", "before user try12121212112"); string easypuzzle = intent2.getextras().getstring("data"); string image_url= intent2.getextras().getstring("image3"); text.settext(easypuzzle); bitmapfactory.options bmoptions1; bmoptions1 = new bitmapfactory.options(); bmoptions1.insamplesize = 1; largeimage large=new largeimage(); bitmap bm = large.loadimage(image_url, bmoptions1); image4.setimagebitmap(bm); log.d("parsing json data", image_url); }
}
// modify getview() produce desire result // set position tag view , retrieve data in onclick
@override public view getview(final int position, view convertview, viewgroup parent) { final data item = mobjects.get(position); view rowview = convertview; if (rowview == null) { layoutinflater inflater = mactivity.getlayoutinflater(); rowview = inflater.inflate(r.layout.item, parent, false); viewholder viewholder = new viewholder(); viewholder.icon = (imageview) rowview.findviewbyid(r.id.image); // viewholder.photo = (imageview) rowview.findviewbyid(r.id.photo); viewholder.title = (textview) rowview.findviewbyid(r.id.title); viewholder.name = (textview) rowview.findviewbyid(r.id.name); viewholder.review = (textview) rowview.findviewbyid(r.id.status); rowview.settag(viewholder); } viewholder holder = (viewholder) rowview.gettag(); holder.title.settext(item.getmtitle()); holder.name.settext(item.getmconcatinate()); holder.review.settext(item.getmreview()); holder.icon.setbackgroundresource(r.drawable.ic_ab); // holder.photo.setbackgroundresource(0); holder.mtask = new downloadimagetask(item.getmimageurl(), holder.icon); if (!holder.mtask.iscancelled()) { holder.mtask.execute(); } viewholder.icon.settag(position); // update position because list view recycle viewholder.icon.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { log.d("parsing json data", "before user try122222"); // perform //object tag= v.gettag(); log.d("parsing json data","abc"); int clickedposition = (integer)v.gettag(); data clickeditem = mobjects.get(clickedposition); string title = clickeditem.getmconcatinate(); string picture=clickeditem.getmimageurl(); intent intent = new intent(v.getcontext(), largeview.class); log.d("parsing json data", "before user try444444"); intent.putextra("data", title); log.d("parsing json data", "before user try555555"); intent.putextra("image3",picture); log.d("parsing json data", "before user try66666666"); v.getcontext().startactivity(intent); log.d("parsing json data", "before user try7777"); } }); // holder.mtask1 = new downloadimagetask1(item.getmimageurl1(), // holder.photo); // if (!holder.mtask1.iscancelled()) { // holder.mtask1.execute(); // } return rowview; }
Comments
Post a Comment