I have a problem and I am stuck at this point. I used recyclerview swipe on each item of recyclerview. What I need to do is to update the textview with 1, 2 and so on as the swipe is moving right just like this.
I am getting the x-axis value with event.getRaw(x) and i need to increase the amount as the x value is increasing from left to right and decrease the count if the swipe is moving from right to left. Here is my code.
holder.swipeLayout.setOnTouchListener(new View.OnTouchListener() {
int downX, upX, initialX = 0, rightX;
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
startX = event.getRawX();
startY = event.getRawY();
break;
case MotionEvent.ACTION_MOVE:
float x = event.getRawX();
float y = event.getRawY();
// Calculate move update. This will happen many times
// during the course of a single movement gesture.
scrollByX = x - startX; // move update x increment
scrollByY = y - startY; // move update y increment
startX = x; // reset initial values to latest
startY = y;
if (scrollByX >= 100 && scrollByX < 150)
holder.leftTextView.setText("1");
if (scrollByX >= 150 && scrollByX < 200)
holder.leftTextView.setText("2");
if (scrollByX >= 200 && scrollByX < 250)
holder.leftTextView.setText("3");
if (scrollByX >= 250 && scrollByX < 300)
holder.leftTextView.setText("4");
if (scrollByX >= 350 && scrollByX < 400)
holder.leftTextView.setText("5");
break;
case MotionEvent.ACTION_UP:
upX = (int) event.getX();
Log.i("event.getX()", " upX " + downX);
holder.swipeLayout.animateReset();
//holder.leftTextView.setText("0");
scrollByX = 0;
scrollByY = 0;
if (upX - downX > 100) {
// swipe right
}
else if (downX - upX > -100) {
// swipe left
}
break;
}
return false;
}
});
Every time i swipe these items sometimes it shows 1 and sometimes 5 meaning it is not behaving properly. Can someone please help me get through this. Thanks.
Try Updating the textView in onTouchEvent()
's case MotionEvent.ACTION_MOVE