Android Button - How To Set Focusable To True And Still Accept Onclick Listener On First Click?
UPDATE I've solved the clicking issue by removing the two focusable lines from the button style and using the onClick event handler to call requestFocusFromTouch(); Unfortunately I
Solution 1:
you can do like this in onClick(View v)
:
.....
v.setFocusableInTouchMode(true);
v.requestFocus();
v.setFocusableInTouchMode(false);
.....//the others
so, v
gets focus and you can do something in onClick()
through setFocusableInTouchMode(false)
, it can accept onClick
at first touch.
Solution 2:
You might need to use an OnFocusChangeListener and then check if the focus event happened when the screen was in touch mode: if it did then it was a user click, otherwise it was from the trackball/trackpad.
Solution 3:
You can use onTouch
. This way you can handle all clicks without having to set OnFocusChangeListener
.
Post a Comment for "Android Button - How To Set Focusable To True And Still Accept Onclick Listener On First Click?"