lundi 25 janvier 2016

GridView with clickable CheckBox: OnCheckedChange not called immediately

I have a GridView of 3 columns populated with a custom BaseAdapter. Each cell of GridView sould contain contain a view with some widgets (an imageView and a textView) and a custom CheckBox for select/unselect cell

<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center" >

    <!-- some views -->

    <CheckBox
        android:id="@+id/my_checkbox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/checkbox_bg"
        android:button="@null"
        android:clickable="true"
        android:scaleType="fitXY" /> 

where checkbox_bg is a selector item:

<selector xmlns:android="http://ift.tt/nIICcg">

    <item android:drawable="@drawable/checked" android:state_checked="true"/>
    <item android:drawable="@drawable/unchecked" android:state_checked="false"/>

</selector>

Inside my adapter, i've implement a OnCheckedChangeListener that perform some task when a checkBox is tapped. After each task, i call notifyDataSetChanged() on adapter.

Now it happens that sometimes (not always) tap on checkbox is not "catched" until i scroll GridView (so onCheckedChanged is not called). Then when i scroll list, all "pending" onCheckedChanged are call.

Theres a way to avoid this behavior (so each time checkbox is tapped, call immediately onCheckedChange )?




Aucun commentaire:

Enregistrer un commentaire