views:

275

answers:

1

I'd like to make a listview that used the ListView.CHOICE_MODE_SINGLE so that the user could only select one thing at a time. However, I want the background to change to the focused color when selected, rather than a checkbox checking off. A good example of what I'm trying to do would be basically any file browser, where the background changes color on each item you select in sequence.

Any help?

A: 

What you'll want to do here is define a class that implements ListAdapter. ListAdapter has a method called getView that the ListActivity will use when it is drawing itself. Define getView so that it returns a view which has a different background color if the item is selected.

UPDATE To respond to a click on an item: In your listActivity, override onListItemClick. In that method, call a method on your adapter to update itself with the click info. Then your adapter should call the onChanged method for each of its observers. If you are not using listActivity, then you can use the setOnItemClickListener method of the ListView to set a callback for this event.

Segfault
Alright, that's almost what I have, everything except setting the background. What I guess I need to know is how would I tell when a row has been pressed?
GuyNoir
Wait, I think I might have gotten it.
GuyNoir
Well, I got the onItemClick I think, but I can't figure out how I would permanently set the background of the row.
GuyNoir
Actually, no, the listview doesn't react to the onItemClick, even though a generic one that I create does.
GuyNoir
see my advice in the update above, GuyNoir.
Segfault
I've tried that, but it doesn't work. I'm thinking it has something to do with my custom Adapter, but I'm, not sure. OnItemFocused works fine, just not onItemClicked.http://www.anddev.org/viewtopic.php?p=36814#36814
GuyNoir