tablelayout - How to get selected row object from Table in Android? -


i using following code create table 3 rows. now, need whenever user selects row want toast value of selected row. sample application, have vector , displaying vector values in tabular format. want implement onitemselected or thing whenever user selects on tablerow need object.

can on this.

protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      tablelayout table = (tablelayout) findviewbyid(r.id.tablelayout01);        table.removeallviews();         string[] valueslist = {"1","2","3"};        for(int i=0;i<3;i++)        {             tablerow row = new tablerow(this);             // count counter 1             row.setlayoutparams(new layoutparams(100,100));             // create new textview             textview t = new textview(this);             t.settextcolor(color.black);             // set text "text xx"                  string value = valueslist[i];             t.settext(value);             row.setonclicklistener(new view.onclicklistener() {                 public void onclick(view view) {                     view.setbackgroundcolor(color.dkgray);                 }                 });               view v = new view(this);             v.setlayoutparams(new tablerow.layoutparams(tablerow.layoutparams.fill_parent, 1));             v.setbackgroundcolor(color.rgb(51, 51, 51));              // add textview , checkbox new tablerow              tablelayout.layoutparams tablerowparams=                       new tablelayout.layoutparams                       (tablelayout.layoutparams.fill_parent,200);                      int leftmargin=10;                     int topmargin=5;                     int rightmargin=10;                     int bottommargin=5;              tablerowparams.setmargins(leftmargin, topmargin, rightmargin, bottommargin);              row.setlayoutparams(tablerowparams);             row.addview(t);              // add tablerow tablelayout             table.addview(row);//,new tablelayout.layoutparams(layoutparams.wrap_content, layoutparams.wrap_content));             table.addview(v);        } } 

thank you.

you may need this:

 row.setonclicklistener(new view.onclicklistener() {                 public void onclick(view view) {                  toast.maketext(getapplicationcontext(), "value "+value,                    toast.length_long).show();                     view.setbackgroundcolor(color.dkgray);                 }                 }); 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -