Change text color of simple ListView Multiple choice Android -
i developing app cricket. requirement this, if select team 1 list of available country name has display , if select country name india list of player india has displayed , in have select multiple players that. have done everything. problem using android.r.layout.simple_list_item_multiple_choice selecting players. using simple list view , background of list black image. , listview that
<listview android:id="@+id/list" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="8.5" android:cachecolorhint="#00000000" />
now problem listview value showing black in color. have black background image. , value black in color. not looking good. how change color of listview values white without changing o custom adapter.
and adapter class
adapter=new arrayadapter<string>(this,android.r.layout.simple_list_item_multiple_choice,playersname); lvview.setchoicemode(listview.choice_mode_multiple); lvview.setadapter(adapter);
you have create custome textview
change color of listview items
, instead of passing default android.r.layout.simple_list_item_multiple_choice
arrayadapter
should pass custom list item xml, has different textcolor attribute.
for example, created custom_list_item.xml under folder layout:
<?xml version="1.0" encoding="utf-8"?> <checkedtextview xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/textview" android:layout_width="fill_parent" android:layout_height="?android:attr/listpreferreditemheight" android:textappearance="?android:attr/textappearancelarge" android:gravity="center_vertical" android:checkmark="?android:attr/listchoiceindicatorsingle" android:paddingleft="6dip" android:paddingright="6dip" android:textcolor="#ff00ff" />
then passed adapter below:
new arrayadapter<string>(this, r.layout.custom_list_item, playersname);
edited:
here code working fine have tested.
lv.setadapter(new arrayadapter<string>(this, r.layout.custom_list_item, playersname)); lv.setbackgroundcolor(color.black); lv.setchoicemode(listview.choice_mode_multiple); lv.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> p_arg0, view p_arg1, int p_arg2, long p_arg3) { my_sel_items = new string("selected items"); sparsebooleanarray = lv.getcheckeditempositions(); (int = 0; < a.size(); i++) { if (a.valueat(i)) { my_sel_items = my_sel_items + "," + (string) lv.getadapter().getitem(i); } } log.v("values", my_sel_items); } });
layout of listview
<listview android:id="@+id/android:list" android:layout_margintop="60dip" android:layout_width="fill_parent" android:layout_height="fill_parent" android:textcolor="#000000" />
Comments
Post a Comment