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 problem seems to come from a property that I can only see in the
XML form
of the layout.Make sure to remove this line at the end of the declaration within the
EditText
XML tags:That should give something like that :
Simplest answer, just add this in parent layout of the XML.
If you have another view on your activity like a
ListView
, you can also do:in your
onResume()
to grab focus from theeditText
.I know this question has been answered but just providing an alternative solution that worked for me :)
Add following in
onCreate
method:Write this line in your Parent Layout...
The simplest thing I did is to set focus on another view in onCreate:
This stopped the soft keyboard coming up and there was no cursor flashing in the EditText.