views:

955

answers:

4

In Android, I want to present the user with a list. When an item on the list is selected some action is performed, and this list item is no longer selectable. It is also 'grayed out' or the like to indicate that it cannot be selected the next time the list is displayed. I have seen the isSelectable() override in Adapter, but I believe this causes the item to be treated as a separator, which causes visual problems. And I have not found a way to 'gray out' an item. Any ideas? Thanks...

+1  A: 

You need the view to be disabled. If you are creating the views just call .setDisabled(boolean) on the top view. Setting the list item to be disabled doesn't work very well in my experience.

Isaac Waller
+1  A: 

I have seen the isSelectable() override in Adapter, but I believe this causes the item to be treated as a separator, which causes visual problems.

What isSelectable() does is literally make it not selectable. The notion of "enabled" is more typically seen with individual widgets, like fields and buttons.

So, functionality-wise, isSelectable() is probably the right answer. You just need to figure out how you want to depict it visually. For example, your rows could integrate a gray translucent View that floats over top of actual contents, set to GONE normally, set to VISIBLE when you make it not selectable.

CommonsWare
A: 

Here is the solution I am using. I set up an OnItemClickListener for my ListView. When an item in the list is clicked, I take the passed in View and call setEnabled(false) on it. This will gray out the item. However, subsequent clicks on this item will still call the onItemClick method. So, you will need to check on each click if the item is enabled/disabled and act accordingly.

meg18019