String[] values = new String[] { "Apple", "Banana", "Cola", "Dove", "Elephant", "Fan", "Grapes", "Horse" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>((this, R.layout.row,R.id.textview1, values);
list.setAdapter(adapter);
(the class which contains the above code extends ListActivity) I want to give different background colors to different row(For example: The background color of the textview1 should be green at position 0, red at position 6, blue at position 7) For this it is said that I need to use custom adapter, but I don't know how to set these particular values Apple,Banana,Cola,...etc to the textview1 using a custom adapter. My xml file row.xml is as shown below
<TextView
android:layout_width="500dp"
android:layout_height="50dp"
android:text="New Text"
android:layout_alignParentTop="true"
android:id="@+id/ListItem"
android:background="@color/color3"
android:gravity="center|left"
android:paddingLeft="5dp"
android:textSize="20dp"
android:textColor="@color/color1" />
I don't know how to implement a customadapter. Can anyone help me to set these values to
the TextView by using a custom adapter and set different background colors to the TextView?