Reputation: 1739
I have simple layout called item
which is
linearlayout
with elements textView
and twice imageButton
Then, I use this layout to generate list (inflate it 10 times). I can't set the same ID on more than one element, so I do not set any.
In each layout item
I can click, on
How to know, which linearlayout, imagebutton was clicked?
Upvotes: 0
Views: 42
Reputation: 62189
I can't set the same ID
Yes, you can't. But you can generate one using generateViewId()
:
From docs:
Generate a value suitable for use in setId(int). This value will not collide with ID values generated at build time by aapt for R.id.
view.setId(View.generateViewId());
And than you can exactly refer to your view.
But this shouldn't be a solution that you should consider to stick with. Instead you should prefer to delegate those logics to RecyclerView
.
Upvotes: 1