Disable swipe gesture on Switch button - Xamarin/Android

Issue :

The problem with switch button in ListView is that when you click on the switch button its SetOnCheckedChangeListener wont get triggered  and when you swipe the button its SetOnClickListener wouldn't get trigger.

Following is the code snippet to disable the swipe gesture for Switch button :

Solution :

Xamarin Android :

1. Implement View.IOnTouchListener
2.viewHolder.SwitchButton.SetOnTouchListener(viewHolder);

//To disable swipe on switch button
        public bool OnTouch(View v, MotionEvent e)
        {
            return e.ActionMasked == MotionEventActions.Move;
        }


Android :

switchButton.setOnTouchListener(new View.OnTouchListener() {
  @Override
  public boolean onTouch(View v, MotionEvent event) {
    return event.getActionMasked() == MotionEvent.ACTION_MOVE;
  }


});

Comments

Popular posts from this blog

ProgressDialog with transparent background XamarinAndroid