Vinayak Bevinakatti Vinayak Bevinakatti - 1 year ago 144
Android Question

How to set focus to a button widget programmatically?

Is it possible to set a focus to a button widget which lies somewhere down in my layout?

of the activity my control/focus should be on that button programmatically.

Answer Source

Yeah it's possible.

Button myBtn = (Button)findViewById(;

or in XML

<Button ...><requestFocus /></Button>

Important Note: The button widget needs to be focusable and focusableInTouchMode. Most widgets are focusable but not focusableInTouchMode by default. So make sure to either set it in code


or in XML