I have a ListView on my Android app screen. In the list view I am showing data from an ArrayList. Now the Arraylist has 3 fields: Id, Name and Status. I need to show on the screen, the Id and the Name and according to the status value, which can be 0, 1 or 2 set the background color for the particular row. I am able to get the ListView with the values on the screen, but I cannot seem to find any example where I can set color of rows in an android list view on create. Can someone please help me? I use a SimpleAdaptor to show the values of the list for now. Thank you in advance. :-)
This is my ListView xml::
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:id="@+id/relativeLayout"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:orientation="vertical"
android:background="#FFEBEB"
tools:context=".MyActivity2">
<ListView
android:id="@+id/listView"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:choiceMode="singleChoice"
android:textAlignment="center"/>
</RelativeLayout>
This is the XML which adds the rows::
<?xml version="1.0" encoding="utf-8"?>
<!-- row.xml -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="4dip"
android:paddingBottom="6dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="left">
<TextView android:id="@+id/TITLE_CELL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:layout_weight="1"
android:height="40dp"
android:textAlignment="center"
android:padding="10dp"/>
<TextView android:id="@+id/FROM_CELL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:height="40dp"
android:textAlignment="center"
android:padding="10dp"/>
</LinearLayout>