Вероятно, вам нужно создать пользовательское представление, расширяющее базовый класс 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;
}
}
});
}