0
我有一個消息應用程序,顯示收到的消息列表,但是我想突出顯示未使用顏色讀取的消息(黃色),而其他列表項仍保留爲默認列表項顏色(白色)。Android ListView項目顏色和滾動問題
我已經設法使用下面的代碼來做到這一點,然而無論何時滾動列表,所有的列表項目,無論它們是否被讀取,都將成爲「高亮」顏色,當他們滾動視圖和然後回到視圖中。
我的目錄選擇:
<?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" />
我在我的陣列適配器後面的代碼,應用設置:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Message_ListItem entry = items.get(position);
....setup list item etc
// Get whether the message has been read
if (!entry.getHasBeenRead()) {
// Set the colour to highlight the listitem
convertView.setBackgroundResource(R.drawable.message_listitem_unread);
}
return convertView;
}
我已經刪除列表中的cacheColorHint設置,以查看如果這有幫助,但這沒有效果。
有什麼辦法可以解決這個問題嗎?
哦,非常感謝,我浪費了我一天的時間,而不是那麼簡單。 – CDrnly