I am inflating a view when a button is pressed. The inflated view is like a dialog box, however when I try to get focus on the dialog box with requestFocus()
, requestFocus() returns false means I am not getting focus on the view, but when I manually tap the inflated view, it recieves focus.
What am I doing wrong?
I clear focus from the button (which is used to inflated the new view) before I call requestFocus on inflated view.
Regards
A possible reason why the View.requestFocus() method returns false (does not successfully request focus) is because of the following reason:
"A view will not actually take focus if it is not focusable (isFocusable() returns false), or if it is focusable and it is not focusable in touch mode (isFocusableInTouchMode()) while the device is in touch mode."
Check if both isFocusable()
and isFocusableInTouchMode()
return true. If not, you could possibly force them by using the setFocusable()
and setFocusableInTouchMethod()
as seen below.
View view;
view.setFocusable(true);
view.setFocusableInTouchMode(true);
view.requestFocus();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With