List element hightlight? - android

I have a list and when I do setOnClickListener for an Item I don't have highlight on Items in a List.
That is not expected behavior because I want to give user a way to see which item was selected on touch.
Is there some way to make it highlighted?
tnx.

Probably you can try to set color to your list item xml. Define your list item color depending on the state. Try this out.

Related

Issue with ListView selected item color

I've created a list view which shows some data. When the user clicks on a specific item, its color should change.
This works, except that every 10th item changes color, not just the item clicked.
try add in your activity
list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
this shloud make your selction single not multiaple selction

Customize checked items in ListView

I have a list view with black text items with single choice mode.
I would like the checked item to be red.
Is there any straightforward way to do this, or do I need to listen for item click callbacks, change the colors manually, etc.?
Thanks
There's nothing that will "automatically" change the background of an entire listview item based on a checkbox, so you'll pretty much have to handle the event.

android select multiple items in ListView?

I have a ListView and I want to select multiple items in the ListView without using CheckedTextView.
Please help !!
You don't really need a CheckBox. All you need is a boolean flag on your list objects. When the user clicks an item you change the state of the flag, and probably the background or text color for that list item.
I never tried it, but I would use ListView with checkbox but non visible.
Perform the setChecked(True) when the user press on an item.
I would also try changing the item background when the checkbox is checked.

Listview item color

My list view is a multiple selection list view. i have to show the selected list view items in one color(say green) and the other items in some other color(red). How to achieve this?
It depends what you mean by showing "items in [...] color." The easiest way to change items' colors is to do it in the Adapter's getView() or bindView() method.
In the onItemSelectListner change the item background to whichever you need.
You could call the setBackgroundColor() method in the select event to change the background color.

Android list with 'grayed out' items

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...
As far as graying out an item. I'm not sure if this is the best way, but it's what I do:
view.setAlpha(75);
view.setBackgroundColor(Color.GRAY);
I'm basically making the item transparent and then setting the background color to gray. If you're reusing your list items you should also change them back to their original state if the condition is not met, i.e.:
view.setAlpha(255);
view.setBackgroundColor(Color.WHITE);
that is, if your original state was no transparency and the background color was white.
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.
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.

Categories

Resources