Skip to content

Instantly share code, notes, and snippets.

@eoinfogarty
Created June 3, 2016 04:08
Show Gist options
  • Save eoinfogarty/6fbec3132855335406d1f8436906bccd to your computer and use it in GitHub Desktop.
Save eoinfogarty/6fbec3132855335406d1f8436906bccd to your computer and use it in GitHub Desktop.
Touch listener to use with a selector
package com.example.app;
import android.view.MotionEvent;
import android.view.View;
public final class SelectorTouchListener implements View.OnTouchListener {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
v.setSelected(true);
return true;
case MotionEvent.ACTION_UP:
v.performClick();
v.setSelected(false);
return true;
case MotionEvent.ACTION_CANCEL:
v.setSelected(false);
return true;
default:
// do nothing
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment