Android ListView item blinks when selected

I am creating a custom ListView as shown below

Main layout

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center">

    <ListView android:id="@+id/listview"
    android:layout_width="0dip"
    android:layout_height="wrap_content"
    android:layout_margin="3dip"  
    android:fadingEdge="none"
    android:soundEffectsEnabled="true"       
    android:clickable="true"                
    android:scrollbars="none"
    android:divider="#ffcccccc"
    android:dividerHeight="1dip"                
    android:layout_weight="1"/>
</LinearLayout>

Custom listview

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@drawable/sellistitem">  
  <TextView
   android:id="@+id/ListItem"       
   android:layout_width="wrap_content"
   android:layout_height="30dip"
   android:layout_margin="1dip"             
   android:textColor="@color/BLACK"
   android:gravity="center_vertical"
   android:layout_alignParentLeft="true"
   android:layout_alignParentTop="true" 
   android:padding="5dip"/>           
</RelativeLayout>

and selector as shown below

<selector 
xmlns:android="http://schemas.android.com/apk/res/android"> 
<item android:state_pressed="true" android:drawable="@drawable/BLUE" /> 
<item android:drawable="@drawable/WHITE" /> 
</selector> 

Removable

 <resources>
    <drawable name="WHITE">#ffffff</drawable>
    <drawable name="BLUE">#ff0033cc</drawable>
 </resources>

Having done this, part of the selection works fine. However, when I click on an item, the selected item blinks twice before actually switching to blue. It does not change to blue, as it should. How to remove this flashing effect?

Yours faithfully,

+3
source share
2 answers

try android:cacheColorHint="#00000000"uplistview

0
source

Selectors are complex in general. Instead, try instead:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:state_pressed="true" 
        android:state_enabled="true"
        android:drawable="@drawable/selected_background" />
  <item android:state_focused="false" 
        android:state_pressed="false" 
        android:state_selected="false"
        android:state_checked="false" 
        android:state_enabled="true" 
        android:state_checkable="false"
        android:drawable="@drawable/normal_background"/>
</selector>

, android:drawable attribute . , @color/background_color.

EDIT:

, "" , , colors.xml. , .

<resources>
    <color name="blue">#ff0033cc</color>
    <color name="white">#ffffff</color>
</resources>
0

All Articles