I have an Activity
in Android, with two elements:
EditText
ListView
When my Activity
starts, the EditText
immediately has input focus (flashing cursor). I don't want any control to have input focus at startup. I tried:
EditText.setSelected(false);
No luck. How can I convince the EditText
to not select itself when the Activity
starts?
The following worked for me in
Manifest
. Write ,At
onCreate
of your Activity, just add useclearFocus()
on your EditText element. For example,And if you want to divert the focus to another element, use
requestFocus()
on that. For example,This is the perfect and most easiest solution.I always use this in my app.
Try clearFocus() instead of
setSelected(false)
. Every view in Android has both focusability and selectability, and I think that you want to just clear the focus.Simple solution: In
AndroidManifest
inActivity
tag useYou can just set "focusable" and "focusable in touch mode" to value true on the first
TextView
of thelayout
. In this way when the activity starts theTextView
will be focused but , due to its nature, you will see nothing focused on the screen and ,of course, there will be no keyboard displayed...