Android ListView Item Colour and Scrolling issue -


i have messaging application displays list of received messages want highlight messages have not been read colour(yellow) whereas other list items remain default list item colour (white).

i have managed using code below whenever scroll list of list items regardless of whether have been read or not "highlight" colour when scroll out of view , view.

my list selector:

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

my code behind in array adapter applies setting:

@override public view getview(int position, view convertview, viewgroup parent) {  message_listitem entry = items.get(position);       ....setup list item etc     // whether message has been read    if (!entry.gethasbeenread()) {        // set colour highlight listitem       convertview.setbackgroundresource(r.drawable.message_listitem_unread);    }    return convertview; } 

i have removed cachecolorhint setting on list see if helps, has no effect.

is there way can solve this?

you forgot else clause in getview() method. list items recycled, once you've set background on unread item, item might reused read item. this:

if (!read) { setbackgroundresource(r.drawable.unread); } else { setbackgroundresource(r.drawable.read); } 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -