我有一個列表視圖,列出了我的Android應用程序中的作業。我想根據他們的工作類型對行進行着色。以下是我用來設置Listview的代碼。分別在列表視圖中設置單獨行的背景顏色
startManagingCursor(cursor);
adapter = new SimpleCursorAdapter(this, R.layout.menu_item, cursor, FROM, TO);
menuList.setAdapter(adapter);
以下是Listview項目的Xml佈局。
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:padding="10sp">
<TextView
android:id="@+id/rowid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/exhibitor_header" />
<TextView
android:id="@+id/rowidtwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/listview_background"
android:layout_below="@+id/rowid"/>
</RelativeLayout>
如何設置列表視圖以與其作業類別相關的顏色顯示每一行。我可以不使用自定義適配器嗎?
我想你不能沒有自定義適配器... 你必須編寫自己的SimpleCursorAdapter ... – krackmoe
使用自定義適配器.. – user370305