Skip to content

Instantly share code, notes, and snippets.

@Coaden
Created January 14, 2015 21:40
Show Gist options
  • Save Coaden/e230be2f1c62161b89d1 to your computer and use it in GitHub Desktop.
Save Coaden/e230be2f1c62161b89d1 to your computer and use it in GitHub Desktop.
Swiping code for Android
View myView = findViewById(R.layout.calender_main);
myView.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
{
oldTouchValue = event.getX();
break;
}
case MotionEvent.ACTION_UP:
{
float currentX = event.getX();
if (oldTouchValue < currentX)
{
// swiped left
previousMonth();
}
if (oldTouchValue > currentX )
{
//swiped right
nextMonth();
}
break;
}
}
return true;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment