2

I have a custom drawable for my listSelection. When I select one Item it gets selected. But on selected when I scroll through the other items (scrolling up/down) the backgroung is flickering and sometimes it is also getting disappeared.

I am including my xml layouts:

ListView:

<ListView
            android:id="@id/listView"
            android:layout_width="100dp"
            android:layout_height="fill_parent"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:listSelector="@drawable/list_selector"
            android:clickable="true"
            android:divider="@drawable/separetor_drawable"
            android:fastScrollEnabled="true"
            android:paddingLeft="15dp"
            android:paddingRight="15dp"
            android:scrollbars="none" >
        </ListView>

drawable layout: list_selector.xml

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

    <corners android:radius="6dp" />

    <solid android:color="@color/grey" />

    <size android:width="50dp" />

</shape>

Also I even I specify shape width the shape automatically fill_parent and that goes for height as well.

Any suggestions?

Debopam Mitra
  • 1,842
  • 4
  • 27
  • 51

3 Answers3

1

//try in your listview attribute as

 android:cacheColorHint = "#00000000"

or

android:cacheColorHint="@android:color/transparent"

at java code, you should use

listView.setCacheColorHint(Color.TRANSPARENT);
Padma Kumar
  • 19,893
  • 17
  • 73
  • 130
  • I set it. The problem is something else let me explain it to you. I have customTextView for my row and drawable for my listSelection. When I select an item it is getting selected but keeping the item selected when I scroll up and down it gets disappeared and again comes back. – Debopam Mitra Jul 19 '12 at 09:56
0

Try this in your listview:

android:listSelector="@android:color/transparent"
android:cacheColorHint="#00000000"
android:focusable="false"
android:focusableInTouchMode="false"
AkashG
  • 7,868
  • 3
  • 28
  • 43
0

Don't know if you got your answer, but we had a similar problem at one point. We fixed it by setting a background on the outer element in our listitem's layout file:

listitem.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/listselector"
...>
....
</RelativeLayout>

and then the drawable.. listselector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@color/blue" />
<item android:state_selected="true" android:state_pressed="false" android:drawable="@color/yellow" />
<item android:state_selected="false" android:state_pressed="false" android:drawable="@color/black" />
</selector>

The background xml file sets values for pressed, selected, and normal states and you can change the colors to other drawable's if you wish. Seemed to fix the weird background flicker problem we were having.

Biojayc
  • 111
  • 8