2011-02-10 203 views
0

我有使用RelativeLayout的,看起來像這樣一個自定義的ListView項...根據SimpleCursorAdapter字段更改ListView項目的背景顏色?

| Time | Title  | 
|  | Description | 

注:左手「時間」與「標題」和「說明是個人‘疊加’TextViews一個全高的TextView 。

ListView項表示從SimpleCursorAdapter從SQLite數據庫提取的電視節目。這工作正常,但下一步是指出程序已計劃進行記錄(該應用程序是基於PC的PVR應用程序的Android客戶端)。

SQL查詢選擇'start_time,title,description,is_set_to_record'前三個文本字段綁定到TextViews,最後一個是布爾值。

看來我可能需要擴展SimpleCursorAdapter,所以如果'is_set_to_record'爲true,那麼我將所有三個TextView的背景顏色設置爲不同的顏色。問題是我不知道我應該在哪裏尋找。

這可能嗎?如果是這樣,任何指向我應該看的地方將不勝感激。

回答

4

在您的擴展SimpleCursorAdapter你可以做這樣的事情。:

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 
    View v = super.getView(position, convertView, parent); 
    Cursor c = getCursor(); 
    c.moveToPosition(position); 
    int col = c.getColumnIndex(is_set_to_record); 
    boolean isSet = c.getInt(col) == 1; 
    if (isSet) { 
     // Set the background color of the text. 
    } else { 
     // Set the background color to something else. 
    } 
    return v; 
} 
+0

我做了稍微不同的方式來你的例子,但它是足夠接近讓我找對了方向。謝謝! – Squonk 2011-02-15 04:07:04