togglebutton - Android Switch button inside RecyclerView's every item -


i working recyclerview , using switch component in every item of it.

<switch     android:id="@+id/list_item_switch"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_marginleft="1dp"     android:layout_marginright="2dp"     android:layout_toleftof="@+id/list_item_price"     android:textoff="@string/switch_save"     android:texton="@string/switch_buy"      android:layout_centervertical="true"      /> 

i using setoncheckedchangelistener event listen state changes

holder.msavebuyswitch.setoncheckedchangelistener(new compoundbutton.oncheckedchangelistener() {     @override     public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) {         if (buttonview.ispressed()) {             moveitemdialog(pos, ischecked);         }     } }); 

use of buttonview.ispressed() identify whether setchecked on switch called user or called programmatically code.

now working perfect when click on switch.

problem - how can make work when slide switch? in android 4.0+ switch component present nice ready made toggle button need know when user slides switch can execute same code executed when pressed. is,

if (buttonview.ispressed()) {     moveitemdialog(pos, ischecked); }   

thank you.

i know question old. i've try android.support.v7.widget.switchcompat it's works sliding.

this sample code , debug log.

<android.support.v7.widget.switchcompat android:id="@+id/saklar_switch" android:layout_gravity="center" android:layout_width="wrap_content" android:layout_height="wrap_content"/> 

debug code

log.d("saklar","pos: "+position+" buttonview.ispressed()"+buttonview.ispressed()); log.d("saklar","pos: "+position+" buttonview = ischeccked? "+ischecked); 

debug result

pos: 2 buttonview.ispressed()true pos: 2 buttonview = ischeccked? true 

ispressed() debug return true while i'm sliding switch button.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -