Android ListView Background Color Changes on Scroll - colorCacheHint Not Fixing Issue

So I'm using a custom listview through an adapter, and on my Nexus 7 everything looks great, but on my HTC Incredible 2 I'm running into an issue where my background color changes. Here's my XML file with the cacheColorHint set. I've also tried with #AA00000. Any suggestions? I also tried setting it in the activity via setCacheColorHint, but nothing's working yet.

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="horizontal"     
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:padding="10dp"
 android:background="#AA000000"
 android:cacheColorHint="#00000000">

 <ImageView android:id="@+id/ExhibitListIcon"
 android:contentDescription="Exhibit List Icon"
 android:layout_width="wrap_content"
 android:layout_height="fill_parent"
 android:gravity="center_vertical"
 android:layout_marginRight="15dp"
 android:layout_marginTop="5dp"
 android:layout_marginBottom="5dp" />

 <TextView android:id="@+id/ExhibitListTitle"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:gravity="center"
 android:textStyle="bold"
 android:textSize="22dp"
 android:textColor="#FFFFFF"
 android:layout_marginTop="5dp"
 android:layout_marginBottom="5dp" />

 </LinearLayout>

Answers


Could you try setting the cachecolorhint in the xml where the Listview is declared, instead of the LinearLayout :

At layout file, use:

android:cacheColorHint="#0000"

OR at java code,use

listView.setCacheColorHint(Color.TRANSPARENT);

Hope this helps!!


Add below line to your listview: android:cacheColorHint="@android:color/transparent"


listView.setCacheColorHint(Color.TRANSPARENT);

Need Your Help

How to override an inherited class property in C#?

c# class inheritance

I learned how to inherit methods by adding virtual to the method in the base class and override in the new class. But what do I do to inherit properties?

unlink vs remove in c++

c++ unix posix erase

What is the difference between remove and unlink functions in C++?