0

I have an android app which uses a ListView. When I click on any item, there is a light gray color which appears and fades out. How can I make this gray color to remain on the selected item instead of disappearing? Please take a look at the gif which shows the scenario which I want to avoid.

Current Scenario Current Scenario

Rutvik Bhatt
  • 3,185
  • 1
  • 16
  • 28
  • you can change the background color clicked item when you click on the `onItemClicklistener` – Bhagyashri Oct 17 '18 at 05:10
  • See https://stackoverflow.com/questions/2562051/listview-item-background-via-custom-selector – Zar E Ahmer Oct 17 '18 at 05:14
  • Add a boolean variable for item state; suppose "isSelected" in modal class for arraylist passed to listview's adapter. Then onItemClick in getView() update this value accordingly further set background for selected/deselected and notifydatasetchanged(). thats it, you are good to go !! – Jaimin Modi Oct 17 '18 at 05:18
  • 1
    Possible duplicate of [Android ListView selected item stay highlighted](https://stackoverflow.com/questions/16189651/android-listview-selected-item-stay-highlighted) – Rajen Raiyarela Oct 17 '18 at 05:22

2 Answers2

0

You can set item Selected according to your need using this method

 listView.setSelection(0);
 listView.getSelectedView().setSelected(true);

OR

 listView.setItemChecked(0, true)
Faiz Mir
  • 599
  • 5
  • 16
0

First of all you need to change background color on clicked.

take reference from here

And then add this line inside your listview's OnItemClickListener

listView.setSelection(int position);
Ashish Kudale
  • 1,230
  • 1
  • 27
  • 51