Created
June 3, 2016 04:08
-
-
Save eoinfogarty/6fbec3132855335406d1f8436906bccd to your computer and use it in GitHub Desktop.
Touch listener to use with a selector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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