listView setitemchecked no funciona
-
24-10-2019 - |
Pregunta
Por alguna razón, SetItemChecked no funciona. ¿Puede alguien ayudarme a arreglar 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);
Y este es el elemento de la lista:
<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"/>
por favor, ayúdame.
Solución
los documentos di esto:
Establece el estado marcado de la posición especificada. El solo es válido si el modo de elección se ha establecido en Choice_Mode_Single o Choice_Mode_Multiple.
Entonces podrías intentarlo:
list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
antes de llamar setItemChecked
.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow