android - Get the value bottommost TextView that add programmatically? -


i adding textview programmatically on linearlayout :

enter image description here

and click on textview , pass ids , texts of textview activity (with sharedpreferences).

but when data sharedpreferences in activity , see data log id , value bottommost textview.

(for example see data of textview_3).

but perhaps had multiple textview on linearlayout , click on 2nd textview or textview me data of bottommost textview.

public class chatpage extends activity { textview[] txt;     @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.chat_page);           txt = new textview[totalpersons];           (int s = 0; s < listofpersons.getlength(); s++) {               txt[s] = new textview(chatpage.this);               if (group.equals("admin")) {                 txt[s].setonclicklistener(new onclicklistener() {                             @override                             public void onclick(view arg0) {                                 startactivity(new intent(                                     chatpage.this,                                     conversationpage.class));                                     editor.putstring("adminid", id);                                     editor.putstring("nameadmin", name);                                     editor.commit();                             }                    });               }               if (group.equals("user")) {                 txt[s].setonclicklistener(new onclicklistener() {                             @override                             public void onclick(view arg0) {                                 startactivity(new intent(                                     chatpage.this,                                     conversationpage.class));                                     editor.putstring("userid", id);                                     editor.putstring("nameuser", name);                                     editor.commit();                             }                    });               }           }     } } 

another activity data :

userid = (shared.getstring("userid", "nullid")); username = (shared.getstring("nameuser", "nullname"));  idadmin = (shared.getstring("adminid", "null_idsharee")); adminname = (shared.getstring("nameadmin", "null_namesharee")); log.i("test", "userid " + userid ); log.i("test", "username " + username ); log.i("test", "idadmin " + idadmin ); log.i("test", "adminname " + adminname ); 

it's java issue, need instantiate new class each on click listener, can't in way. create private class in code

 private class myonclicklistener implements onclicklistener {     private final string    mid;      public myonclicklistener(string id) {         mid= id;     }      public void onclick(view v) {         intent intent= new intent(getapplicationcontext(), activity.class);         intent.putextra("current_post_id", mid);         startactivity(intent);     }  } 

then

textview.setonclicklistener(new myonclicklistener(id)); 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -