android - how to show list view record in textview on setOnItemClickListener -
i have created simple list view,what want when user click on list view,selected record should show in text view in code work properly,but problem when user again click want show record in second text view,please give me idea/code how this..please please me...i new in android..
public class mainactivity extends activity { string item[]=new string[]{"rk","kk","kk","ll","mm","uu"}; textview tv,tv1,tv2,tv3,tv4; listview li; protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); li=(listview)findviewbyid(r.id.listview1); tv=(textview)findviewbyid(r.id.settext);\ tv1=(textview)findviewbyid(r.id.settext1); tv2=(textview)findviewbyid(r.id.settext2); tv3=(textview)findviewbyid(r.id.settext3); tv4=(textview)findviewbyid(r.id.settext4); arrayadapter<string> adapter=new arrayadapter<string> (this,android.r.layout.simple_list_item_1,android.r.id.text1, item); li.setadapter(adapter); li.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> arg0, view arg1, int position,long arg3) { // todo auto-generated method stub int itm=position; toast.maketext(getapplicationcontext(),""+itm+""+li.getitematposition(position),40).show(); tv.settext(""+li.getitematposition(position)); } });
there many ways can deal it.
arraylist<boolean> firsttimers = new arraylist<boolean>(); (int =0; i< item.length(); i++){ firsttimers.add(false); } li.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> arg0, view arg1, int position,long arg3) { // todo auto-generated method stub if( !firsttimers.get(position ){ int itm=position; toast.maketext(getapplicationcontext(),""+itm+""+li.getitematposition(position),40).show(); tv.settext(""+li.getitematposition(position)); firsttimers.set(position,true); }else{ // show in other textview } } });
Comments
Post a Comment