Aravind
Aravind

Reputation: 590

Android: Getting a reference to an inflated view/ Setting a unique id to the inflated view

I'm writing a poll application.

I have a main_view.xml and poll_item_view.xml. main_view.xml is just the container for all the poll results and poll_item_view is one particular poll result. I'm inflating the poll_item_view.xml multiple times inside the main-view to show a list of poll results.

Now periodically I need refresh the poll results, as and when people vote. I need a way to refer to each of the poll_item I inflated inside the main_view. Is there a wasy to set a unique id to each poll item which I can later use to get a reference to a particual poll item.

Thanks, Aryan

Upvotes: 1

Views: 625

Answers (2)

miguel_ibero
miguel_ibero

Reputation: 1024

You could use View.setTag and View.getTag .

Upvotes: 2

Alex Klimashevsky
Alex Klimashevsky

Reputation: 2495

If you use onClickListener of your view you have a ref. to this view. If you update items outside, you can use indexes and getChildAt method.
Also good method to create wrappers of view with ref. to fields for quick access and update

Upvotes: 1

Related Questions