2010-06-25 65 views

回答

1

它似乎相當愚蠢的API缺乏這樣的基本功能,但我認爲你的解決方案將不得不定義自己的ListAdapter

XML:

<android:id="@+id/label" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textColor="#rrggbb" 
/> 

自定義列表活動:

public void onCreate(Bundle bundle) { 
    super.onCreate(bundle); 
    setContentView(R.layout.main); 
    setListAdapter(new ArrayAdapter(this, R.layout.row, R.id.label, items)); 
} 

如果基於列表項(禁用/選擇/點擊等)的狀態,遇到問題你必須給android:listSelector設定爲是由StateListDrawable集合的自定義選擇:

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_enabled="false" android:state_focused="true" 
     android:drawable="@drawable/item_disabled" /> 
    <item android:state_pressed="true" 
     android:drawable="@drawable/item_pressed" /> 
</selector>