android - Why share text The Displaced in listview -
android - Why share text The Displaced in listview -
in next code when share text img_share, not share text in right position illustration when shared text of sec item,shared text of 5th item ! why??
i used adapter list
this adapter:
public class faslhaadapter1 extends arrayadapter<faslha> { faslha fasl; list<faslha> faslha; context c; public faslhaadapter1(context c, list<faslha> faslha) { super(c, android.r.id.content, faslha); this.c = c; this.faslha = faslha; } @override public view getview(int position, view convertview, viewgroup parent) { // laye mun ro tarif mikonim layoutinflater vi = (layoutinflater) c .getsystemservice(context.layout_inflater_service); view view = vi.inflate(r.layout.itemlistsms, null); fasl = faslha.get(position); final textview tvdastan = (textview) view.findviewbyid(r.id.itm_namdastan); final imageview img_share = (imageview) view.findviewbyid(r.id.eshterak); tvdastan.settext(fasl.getonvan()); img_share.setonclicklistener(new onclicklistener() { @override public void onclick(view arg0) { intent shareintent = new intent(intent.action_send); shareintent.settype("text/plain"); shareintent.putextra(intent.extra_text, fasl.getonvan() + "\n گروه مذهبی آسمان"); c.startactivity(intent.createchooser(shareintent, "اشتراک... ")); //code marbut share ro vasatun tu site mizaram } }); homecoming view; } }
and list:
public class listsms extends listactivity { dbadapter db; list<faslha> faslha; listview lv, lst; boolean isall; context context; string title; faslha faslhaa; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.listsms); context = this; lst = getlistview(); db = new dbadapter(getbasecontext()); db.open(); intent intent = getintent(); title = intent.getstringextra("title"); faslha = db.geta(title); } @override protected void onlistitemclick(listview l, view v, int position, long id) { super.onlistitemclick(l, v, position, id); } public void copydb(inputstream inputstream, outputstream outputstream) throws ioexception { // ---copy 1k bytes @ time--- byte[] buffer = new byte[1024]; int length; while ((length = inputstream.read(buffer)) > 0) { outputstream.write(buffer, 0, length); } inputstream.close(); outputstream.close(); } public void refreshdisplay() { if(lst.getadapter() == null){ arrayadapter<faslha> adapter = new faslhaadapter1(this, faslha); setlistadapter(adapter); } } @override protected void onpause() { super.onpause(); db.close(); } @override protected void onresume() { super.onresume(); db.open(); refreshdisplay(); } }
because getting here: fasl.getonvan(). field fasl changing while adapter populating view , it's equals lastly item on screen when click button.
the simple solution is:
@override public view getview(int position, view convertview, viewgroup parent) { // laye mun ro tarif mikonim layoutinflater vi = (layoutinflater) c .getsystemservice(context.layout_inflater_service); view view = vi.inflate(r.layout.itemlistsms, null); final faslha fasl = faslha.get(position); // create final variable. final textview tvdastan = (textview) view.findviewbyid(r.id.itm_namdastan); final imageview img_share = (imageview) view.findviewbyid(r.id.eshterak); tvdastan.settext(fasl.getonvan()); img_share.setonclicklistener(new onclicklistener() { @override public void onclick(view arg0) { intent shareintent = new intent(intent.action_send); shareintent.settype("text/plain"); shareintent.putextra(intent.extra_text, fasl.getonvan() + "\n گروه مذهبی آسمان"); c.startactivity(intent.createchooser(shareintent, "اشتراک... ")); //code marbut share ro vasatun tu site mizaram } }); homecoming view; }
and remove field fasl adapter class.
android image android-listview android-view
Comments
Post a Comment