This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
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!
 
Don't get me started about those stupid light bulbs.
 
subject: How to refer a view in a line inside a ListView ?