我有一个SQLite外部数据库。有一个TextView可以显示数据库的记录。在此TextView中获取和显示数据没有问题。现在我想做点别的。当用户滑动TextView时,我希望下一条记录显示在TextView中。当用户向后滑动时,将显示前一个记录。预先感谢。
答案 0 :(得分:0)
可能您需要创建一个扩展TextView基类的自定义视图。
class SwipeableTextView extends TextView {
//here is three constructors from View class
public SwipeableTextView(Context context) {
super(context);
}
public SwipeableTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SwipeableTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
}
MainActivity.java
class MainActivity {
int startX,
starty = 0;
//inside onCreate
TextView tv = findViewById(R.id.myTextView)
tv.setOnTouchListener(new OnTouchListener {
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: //called when you touch view
startx = event.x;
starty = event.y;
return true;
break;
case MotionEvent.ACTION_UP: //when you lift up your finger from viev
return true;
break;
case MotionEvent.ACTION_MOVE: //when you finger on view
int differenceX,
differenceY;
differenceX = startX - event.x;
if (Math.abs(differenceX) > 50)
changeTextMethod();
return true;
}
}
});
}