I create a app with a database.in one activity with swipe to left and right the textView go to previous and next row of table. the problem it is that i want to do transition or animate in left and right swipe for next and previous row. some part of my activity code:
@Override
public boolean onTouchEvent(MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) {
return true;
}
return super.onTouchEvent(event);
}
private void onLeftSwipe() {
movePrev();
}
private void onRightSwipe() {
moveNext();
}
// Private class for gestures
private class SwipeGestureDetector
extends GestureDetector.SimpleOnGestureListener {
// Swipe properties, you can change it to make the swipe
// longer or shorter and speed
private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_MAX_OFF_PATH = 200;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2,
float velocityX, float velocityY) {
try {
float diffAbs = Math.abs(e1.getY() - e2.getY());
float diff = e1.getX() - e2.getX();
if (diffAbs > SWIPE_MAX_OFF_PATH)
return false;
// Left swipe
if (diff > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
nokteb1list.this.onLeftSwipe();
// Right swipe
} else if (-diff > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
nokteb1list.this.onRightSwipe();
}
} catch (Exception e) {
Log.e("YourActivity", "Error on gestures");
}
return false;
}
}
protected void openDatabase() {
db = openOrCreateDatabase("Listo.db", Context.MODE_PRIVATE, null);
}
protected void showRecords() {
String name = c.getString(1);
noktehtext.setText(name);
}
protected void moveNext() {
if (!c.isLast())
c.moveToNext();
showRecords();
}
protected void movePrev() {
if (!c.isFirst())
c.moveToPrevious();
showRecords();
}