Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

listview setItemChecked doesn't work

For some reason setItemChecked doesn't work. can some one help me fix ti ?

String[] str = getResources().getStringArray(R.array.brush_type);
sizeArrayAdapter = new ArrayAdapter<String>(this.getContext(), R.layout.drawing_list_item, str);

listType = SIZE_LIST;
listView.setAdapter(sizeArrayAdapter);

// Populate the listView
listView.setItemChecked(4,true);

and this is the list item:

<CheckedTextView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/drawingCheckedTextView"
        android:layout_width="fill_parent"
        android:layout_height="?android:attr/listPreferredItemHeight"
        android:gravity="center_vertical"
        android:checkMark="?android:attr/listChoiceIndicatorSingle"
        android:background="@drawable/list_panel"
        android:paddingLeft="6dip"
        android:paddingRight="6dip"/>

please help me.

like image 931
Mark T Avatar asked Mar 14 '11 19:03

Mark T


1 Answers

The docs say this:

Sets the checked state of the specified position. The is only valid if the choice mode has been set to CHOICE_MODE_SINGLE or CHOICE_MODE_MULTIPLE.

So you might try:

list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

before calling setItemChecked.

like image 108
Matthew Willis Avatar answered Sep 24 '22 03:09

Matthew Willis