aspose file tools*
The moose likes Android and the fly likes How to refer a view in a line inside a ListView ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "How to refer a view in a line inside a ListView ?" Watch "How to refer a view in a line inside a ListView ?" New topic
Author

How to refer a view in a line inside a ListView ?

Alessandro Camel
Ranch Hand

Joined: Jul 03, 2009
Posts: 35
I generated a ListView (using a simple BaseAdapter) where each line is made of:

ButtonDOWN -- TextArea -- ButtonUP

The idea is that when clicking on the buttons the value of the textarea must increase|decrease.

this is the XML of the single line:



In the Activity this is the OnClickButton code:



The problem is when two or more lines are listed, and I click on the buttons, only the textarea of the first line is updated,
even if I click on the buttons of the other lines!

How I can point to the right textarea ?
Hardik Trivedi
Ranch Hand

Joined: Jan 30, 2010
Posts: 252
Use Custom Adapter. In that you will be having getView Method in which you have inflated view for each list item. Implement you button's click event in that getView method only. So each button will have a separate click listener.Implement logic in that.

Hope you got your answer.

Or correct me if I got your question in wrong manner.
Alessandro Camel
Ranch Hand

Joined: Jul 03, 2009
Posts: 35
Hardik Trivedi wrote:Use Custom Adapter. In that you will be having getView Method in which you have inflated view for each list item. Implement you button's click event in that getView method only. So each button will have a separate click listener.Implement logic in that.

Hope you got your answer.

Or correct me if I got your question in wrong manner.


Thanks Hardik,indeed this is the rigth solution.
Implementing the event handlers inside the getView method is the rigth way to solve this!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to refer a view in a line inside a ListView ?