android - Dynamic get id of element -


i have simple layout called item linearlayout elements textview , twice imagebutton

then, use layout generate list (inflate 10 times). can't set same id on more 1 element, not set any.

in each layout item can click, on

  • linearlayout
  • first imagebutton
  • second imagebutton

how know, linearlayout, imagebutton clicked?

i can't set same id

yes, can't. can generate 1 using generateviewid():

from docs:

generate value suitable use in setid(int). value not collide id values generated @ build time aapt r.id.

view.setid(view.generateviewid()); 

and can refer view.

but shouldn't solution should consider stick with. instead should prefer delegate logics recyclerview.


Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -