Customize checked items in ListView - android

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.

Related

ListView does not highlight on programmatic setSelection

Please distinguish that my ListView does highlight when a user clicks on an Item. The problem is when the user first opens my Activity, I want to preselect an item so I use listView.setSelection(position). But doing this does not cause the view to highlight. Now I understand the documentation for setSelection says
If in touch mode, the item will not be selected...
What I am looking for is a workaround to that particular problem. Thanks.
You can change choice mode to :
Listview.setChoiceMode(ListView.CHOICE_MODE_SINGLE)
and you can set selection color aswell :
Listview.setSelector(android.R.color.darker_gray);

How to mark an element visually in ListView the user clicked on?

I have a ListView with a custom adapter. I'd like to visually mark the list element the user clicked on by changing it's background permanently (until the user clicks on another element that is). How do I achieve that? I believe that there's a built-in feature inside LisView for this, but I had no luck finding it yet.
By default ListView animates the background color of the list-element clicked, I just want that modified color to "stay". I've already set the ListView's ChoiceMode to single choice, but it doesn't affect it visually.
Have you tried ListView.setSelector?

ListView Item and OnClick problem

When you touch some grid or listview items in an android app, he change the background color telling you that you have pressed it.
I'm having a problem in my app. When I create that a listview for instance, and I press it in my phone, he change color, but if I set the OnClick property, the item dont change it color. Whats wrong? The OnClick works as its suppose.
Thanks
Generally with ListView you want to use an OnItemClickListener.
This gives you a chance to perform an action based on the position in the list that was clicked.
If you need access to the view adapter from within onItemClick then you can use AdapterView#getAdapter() on the AdapterView that is supplied to you.

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.

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