listview setItemChecked ne fonctionne pas
-
24-10-2019 - |
Question
Pour une raison setItemChecked ne fonctionne pas. quelqu'un peut me aider à corriger 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);
et c'est l'élément de liste:
<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"/>
S'il vous plaît aidez-moi.
La solution
Le docs par exemple ceci:
Définit l'état vérifié du position spécifiée. Le est uniquement valable si le mode de choix a été réglé CHOICE_MODE_SINGLE ou CHOICE_MODE_MULTIPLE.
Vous pouvez essayer:
list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
avant d'appeler setItemChecked
.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow