I have a listview
with CheckedTextViews
as records, when clicking on an item I can see that the status of the CheckedTextView
has switched but the Checkmark
is never hide.
This is my XML of the listView
<ListView
android:id="@+id/listFilters"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingStart="10dp"
android:choiceMode="multipleChoice" />
and this is the XML of the records :
<CheckedTextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/filter"
android:layout_width="match_parent"
android:layout_height="60dp"
android:minHeight="60dp"
android:text="filter1"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:gravity="center_vertical"
android:checkMark="@drawable/icon_blue_checkmark" />
This is my OnItemClick Listener :
@Override
public void onItemClick (AdapterView<?> parent, View view, int position, long id) {
Filter filter = (Filter) adapter.getItem (position);
boolean isSelected = !filter.isSelected ();
filter.setSelected (isSelected);
CheckedTextView ctv = (CheckedTextView)listView.getChildAt (position);
ctv.toggle ();
// shows that the status of the CheckedTextView has switched successfully
Toast.makeText (
getActivity (),
"CheckedTextView status : " + ctv.isChecked (),
Toast.LENGTH_SHORT
).show();
}
What am I doing wrong ? Thanks.
EDIT :
I have just noticed that when replacing my custom checkmark drawable with : android:checkMark="?android:attr/listChoiceIndicatorMultiple"
It works fine. Any idea ?