Reputation: 433
My problem is similar to question posted here. I want an Android button to stay pressed. I cannot follow the solution provided because onClick
will be called when a button is pressed via keyboard or trackball and i need to handle that.
I tried setting button.setPressed(true);
in onClick
callback , but it doesn't seem to work. Is there a way to do this?
Upvotes: 0
Views: 554
Reputation: 1373
Try this it will work...
singIn.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction()==MotionEvent.ACTION_DOWN) return true;
if(event.getAction()!=MotionEvent.ACTION_UP) return false;
//DO SOMETHING!!
singIn.setPressed(true);
return true;
}
});
Upvotes: 2
Reputation: 1513
Try sending a touch event to the button like this:
MotionEvent down = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, 0, 0, 0);
yourButton.dispatchTouchEvent(down);
Upvotes: 1