There is a set of buttons, all clicks are processed using OnClick , and there are no problems with them. Two buttons are processed using OnTouch , and when you click on them the background of the button does not change.
- How can I make the background change if
onTouchcannot removeonTouch? - Is it possible to do action processing in
OnClick
Here is the code
button_left.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { int RightEngine = 0 , LeftEngine = 0; currentLog++; if(currentLog>100) currentLog= 100; RightEngine = (int) (21.7*Math.log((double)currentLog)); LeftEngine = (int) -(21.7*Math.log((double)currentLog)); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: // нажатие flagButton = true; label = false; leftEngineVal = LeftEngine; rightEngineVal = RightEngine; break; case MotionEvent.ACTION_MOVE: label = false; flagButton = true; leftEngineVal = LeftEngine; rightEngineVal = RightEngine; break; case MotionEvent.ACTION_UP:// отпускание flagButton = false; label = true; currentLog=0; leftEngineVal=rightEngineVal=0; break; } return true; } }); Same is buttonRight
selector
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/left_pressed" /> <item android:state_pressed="false" android:drawable="@drawable/left" /> </selector> PS I am new to Android, do not judge strictly. Replacing pictures is done using selector, from actions I need MotionEvent.ACTION_DOWN , MotionEvent.ACTION_MOVE and MotionEvent.ACTION_UP