'press sequence of buttons by sliding the finger on them?
I have a 2 dimensional recyclerview that contains buttons. when the user clicks on the button it changes the layout color to green and vice versa.
I'm trying to add a feature that allows the user to slide the finger on the buttons row, and make the buttons get pressed. couldn't find documentation about it. I don't want to use slider widget because I would like to keep the buttons formation. any ideas?
thanks
This is my setOnClickListener for the button ( the button is a circular layout):
holder.linearLayout.setOnClickListener(new View.OnClickListener() {
Intent intent = new Intent(mContext,WorkoutInterface.class);
@Override
public void onClick(View v) {
if(isPressed[0] ==false){//check if the button is already pressed
isPressed[0] =true;
actualReps+=1;// add rep count to the actual reps variable
if(workout.pressedButtons==null){//save the number of presses in list
workout.pressedButtons="";
}else {
workout.pressedButtons+=","+String.valueOf(verticalIndex) + String.valueOf(position);
buttonColorCheck(holder, position, verticalIndex);//if button is pressed in the past, keep it green
}
}else{
holder.linearLayout.setBackgroundColor(Color.argb(255,166, 172, 175) );
isPressed[0] =false;
actualReps-=1;
changeButtonStatus(String.valueOf(verticalIndex)+String.valueOf(position));
}
}
});
Solution 1:[1]
you have to create it manually
public Rect btn1Rect= new Rect((int) btn1.getX(), (int) btn1.getY(), (int) btn1.getX() + btn1.getWidth(), (int) btn1.getY() + btn1.getHeight()); //bound of button 1
View.OnTouchListener buttonTouch = new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getActionMasked();
int x= (int) event.getRawX(),y= (int) event.getRawY();
switch (action) {
case MotionEvent.ACTION_DOWN:
break;
case MotionEvent.ACTION_MOVE:
if(btn1Rect.contains(x,y)){
Log.d(TAG, "onTouch: your touch contains btn1 bound");
}
break;
case MotionEvent.ACTION_UP:
break;
}
return true;
}
};
make sure that set touch listener to your buttons and remove click listener from it.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | EAS |

