Focusing an EditText Request

I design the login page as:

UserName: ..... Password: ..... LoginButton 

When the action starts, I want the focus to move to the "UserName" text box and the keyboard will appear.

I am using the following code:

  boolean checkFocus=user.requestFocus(); Log.i("CheckFocus", ""+checkFocus); if(checkFocus==true) { InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); mgr.showSoftInput(user, InputMethodManager.SHOW_IMPLICIT); } 

I don’t understand where to write this code so that the keyboard is displayed when the activity starts and focuses in the "UserName" editing window. Can anyone guide me?

+42
android android-layout android-edittext
Nov 10 2018-11-11T00:
source share
5 answers

Programatically:

 edittext.requestFocus(); 

Via xml:

 <EditText...> <requestFocus /> </EditText> 

Or call the onClick method manually.

+140
Nov 10 '11 at
source share

Yes, I got an answer. Just edit the manifest file as:

  <activity android:name=".MainActivity" android:label="@string/app_name" android:windowSoftInputMode="stateAlwaysVisible" /> 

and set EditText.requestFocus() to onCreate() ..

Thank..

+19
Nov 10 '11 at 11:47
source share

youredittext.requestFocus() call it from action

 oncreate(); 

and use the code above

+4
Nov 10 2018-11-11T00:
source share

He worked for me as follows.

 ed1.requestFocus(); return; //FaΓ§a um return para retornar o foco 
+1
Nov 14 '16 at 2:59
source share

edittext.requestFocus() works for me in my Activity and Fragment

0
Aug 01 '15 at 5:39 on
source share



All Articles