How to open a keyboard when you "focus" on an Edittext?

Asked

Viewed 2,422 times

1

I have an Edittext where I used the requestFocus() to get his Focus. I put the setFocus(true) and the setFocusableInTouchMode also.

When I open Activity, requestFocus() works, but does not open the keyboard and the Textwatcher that I use in the same Activity does not receive the data I type in Textview (When I click on Edittext it opens the keyboard).

Does anyone know what it can be?

  • Can you explain better what you want to do? And some code would also help a lot.

4 answers

2

To show the keyboard you can do so:

EditText editText = (EditText) findViewById(R.id.editText);
editText.requestFocus();
getDialog().getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);

or alternatively (I usually use it like this):

EditText editText = (EditText) findViewById(R.id.editText);
InputMethodManager imm=(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);

0

if Voce has only one Edittext in its Activity it is sufficient to use the following Attributes in its manifest.xml

 android:windowSoftInputMode="stateAlwaysVisible"

where ? :

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

    ...................

  </activity>

it will not be necessary to use setFocus(true) , setFocusableInTouchMode() or the requestFocus()

0

For you to focus on Edittext:

editText.requestFocus();

And to reverse (take):

editText.clearFocus();

0

Checks whether in the Manifest has that tag on Activity:

   android:windowSoftInputMode="stateAlwaysHidden"

If you have, remove.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.