android--unable to add listener to inflated table- -


i have table defined in xml , row defining view xml. let's need populate table 5 rows. running following code:

  final viewgroup table = (tablelayout)findviewbyid(r.id.table);    view row = null;    textview title = null;    for(int i=0; i<5; i++)    {         row = layoutinflater.from(this).inflate(r.layout.row, null, false);         title = (textview)row.findviewbyid(r.id.text_title);         title.settext("val");        imageview x= (imageview)itemview.findviewbyid(r.id.remove);        x.setonclicklistener(delimg);         table.addview(row);    }   private onclicklistener delimg = new onclicklistener() {        @override     public void onclick(view arg0) {         // todo auto-generated method stub          textview tv = (textview) findviewbyid(r.id.pname);                        tv.settext("deleted item!");        }  };  

it works fine when try add onclicklistener image, changes first row , not corressponding row. please help.

where's itemview coming from? presuming imageview want set listener inside row, might try changing from:

imageview x= (imageview)itemview.findviewbyid(r.id.remove); 

to

imageview x= (imageview) row.findviewbyid(r.id.remove); 

does work change?


edit: think made wrong assumption on problem here. thought had single textview called pname, outside table. if pressed image on row 0, text update, if pressed row 1-4, nothing happening. didn't see cause that.

i may have misread "it changes first row." have pname in each row, , text changes on first row regardless of row click? if so, need change onclick() to:

textview tv = (textview) arg0.findviewbyid(r.id.pname);            tv.settext("deleted item!");   

otherwise, it's finding first item id in entire activity.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -