Skip to content Skip to sidebar Skip to footer

Selected List Item Color Moves On Scrolling The ListView In Android

In my Android application I am using listview. The code for list view is as follows

Solution 1:

seems uncleared states in selector causing this . use one like

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 

  <!-- Selected --> 
  <item 
    android:state_focused="true" 
    android:state_selected="false" 
    android:drawable="@drawable/focused"/> 

  <!-- Pressed -->
  <item 
    android:state_selected="true" 
    android:state_focused="false"
    android:drawable="@drawable/pressed" /> 

<!-- default -->
  <item  android:drawable="@drawable/default" /> 

</selector> 

Solution 2:

add line in getView() method; convertView.setBackgroundResource(selectedItemInAactivityList.contains.(arrayListSetInAdaptor.get(position) ? r.drawable.selected : R.drawable.transperant));

This one line solved your problem


Solution 3:

Store clicked/selected positions in a set or array in your onItemClick() method. Write code to handle color in getview() method of your adapter using stored positions.


Post a Comment for "Selected List Item Color Moves On Scrolling The ListView In Android"