Listview with Buttons problem

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Listview with Buttons problem

Postby Croccy22 » Thu Aug 13, 2009 11:24 pm

Hi all,

I have an activity that extends ListActivity. I then have a Class which uses View Inflater so I cn fill the list rows out differently depending on values from a cursor adapter.

So for example if one of the "Devices" in my database is a lamp module then create a row with four buttons, off,dim,bright and on.

This all works fine so far. So now I need to deal with the button presses. Within the getView() I define the button for the row and then set an onclick listener for that button.

To test this I put an AlerDialog in the onclick event for the off button. Now when I click an off button on one of he rows I get an Alert Showing up. Great I thought!!

But now the problem is how do I tell which one of the Off buttons was pressed? I need my AlertDialog to show a value from the cursor adapter that matchs the row from which the off button was pressed.

So if I have three rows, called, Light, TV and Heater. And I press the off button on the Light Row I want the alertDialog to say "Light".

I just can't seem to figure ot how to get a relevant value out of it. Everything I tired just returned the last value that the cursor adapter retrieved rather than the one relevant to the row. So in he example above every off button I press just displays Heater.

Any help would be greatly appreciated.

Matt.
Croccy22
Developer
Developer
 
Posts: 31
Joined: Wed Dec 03, 2008 3:15 pm

Top

Postby Croccy22 » Fri Aug 14, 2009 7:21 am

Ok, I think I can simplify my question a fair bit.

Lets say I have a listview that containsmultiple rows, each with a button callled R.id.Mybutton and a textview called textview.

The user clicks on a button on the listview, how can I tell which one of the buttons they pressed when they all have the same ID since the were gererated by the list view?

There must be a unique ID returned that links that button to the row which was pressed? but I can't find it!

Help!

Matt.
Croccy22
Developer
Developer
 
Posts: 31
Joined: Wed Dec 03, 2008 3:15 pm

Postby Croccy22 » Fri Aug 14, 2009 2:28 pm

Is this really difficult to do or is it really simple??

I cannot find any code on the net that has a list view with buttons that work?

I don't know if I can't find the code because no-one has done it or because everyone has done it and it is really easy so no-one metions it!

The bit I don't understand is that if you have a listview that has a button, each row in the listview will contain an instance of that same button. So when you push the button how do you know which instance of the button was just pressed?
Croccy22
Developer
Developer
 
Posts: 31
Joined: Wed Dec 03, 2008 3:15 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Exabot [Bot] and 10 guests