0
votes

I have the multiple choice listview with default background color as black and text color as white.When I change the background color white,I couldn't able to change the multiple choice listview text color.Other than customization listview how to change the text color?

enter image description here

Listview XMl:

<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:choiceMode="multipleChoice"/>

Android code:

 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, My_arr);
2
please post your code,Shayan Pourvatan
Try out with custom layout.GrIsHu
Its always a better approach to create a custom layout for list element. If you want to still go with this approach and change the color, loop over all the child of list and try this ListView.getChildAt(0).findViewById(android.R.id.text1).setTextColor("your color");Hardik4560
@all Without custom layout,change the text color is possible or not?.I don't know..Ram

2 Answers

1
votes

Try to implement your own ArrayAdapter and override the getView() method:

public class MyAdapter extends ArrayAdapter<String> {

public MyAdapter(Context context, int p_resID, ArrayList<String> p_items) {
    super(context, p_resID, p_items);                       
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View v = super.getView(position, convertView, parent);
        ((TextView) v).setTextColor(Color.GREEN); 
    return v;
}

}

Don't forget to provide an alternative else clause to set the color to the default so you don't have problems when you're dealing with a recycled row. Then in your activity:

 setListAdapter(new MyAdapter(this,R.layout.list_item,My_arr));

list_item.xml

 <?xml version="1.0" encoding="utf-8"?>
  <CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    android:layout_width="match_parent"
    android:layout_height="?android:attr/listPreferredItemHeightSmall"
    android:textAppearance="?android:attr/textAppearanceListItemSmall"
    android:gravity="center_vertical"
    android:checkMark="?android:attr/listChoiceIndicatorMultiple"
    android:paddingStart="?android:attr/listPreferredItemPaddingStart"
    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
    android:textColor="#FF0000"
   />
0
votes

You can easily do this thing from which Layout the text comes on this Layout change the color of TextView in this manner android:textColor="hashcode of color"

Enjoy!!!