Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scrolling a ListView changes everything from White to Black [duplicate]

Tags:

android

I have a custom list view and I want the background of the list to be white, so I do something like this which works great.

listView = (ListView) this.findViewById(R.id.listview); listView.setBackgroundColor(Color.WHITE); 

The problem is when you scroll the list the background of all the list items changes to black, which looks horrible.

I tried in my list view setting the background color to white. When I inflate the view I also tried setting the background color to white:

view.setBackgroundColor(Color.WHITE); 

Both of these fix the problem of the scrolling background color, but now the item doesn't appear to be clickable even though it is. What I mean by that is the onClick still works fine, but the background doesn't flash to orange to let the user know he clicked it.

How can I have a white background in a list view, that stays white while scrolling, and does the normal list acitvity orange click background?

Thanks!

like image 203
Cameron McBride Avatar asked Jun 10 '10 05:06

Cameron McBride


2 Answers

The solution is very simple, you also need to set the cache color hint to white: setCacheColorHint(Color.WHITE). You don't need to change the list items' background color.

like image 141
Romain Guy Avatar answered Sep 29 '22 09:09

Romain Guy


ListView lv = getListView(); setCacheColorHint(0); 

Set the cache color hint to zero.

like image 35
Sababado Avatar answered Sep 29 '22 09:09

Sababado