Reputation: 158
In my XML code I have 2 EditText
s, the first one for username, the second one for password. I am actually using SharedPreferences
to always keep username but I want to request focus on my password EditText
.
I tried adding this to my password EditText
XML code:
<requestFocus></requestFocus>
In my OnCreate code:
etUserName.clearFocus();
etPassword.setFocusableInTouchMode(true);
etPassword.requestFocus();
The above works, if I also do etUserName.setFocusable(false);
. It "works" (focus is on the second EditText
) but I can't change the value of etUserName
in the UI.
Upvotes: 0
Views: 402
Reputation: 9388
Remove the below lines:
etUserName.clearFocus();
etPassword.setFocusableInTouchMode(true);
etPassword.requestFocus();
Just add the below code in your activity:
etPassword.requestFocus();
Or
You can do it from XML:
Just add the below attribute for the password EditText.
android:focusable=true
Upvotes: 1