EditText onClick does not show virtual keyboard

If I click on my EditText, the virtual keyboard simply will not appear. The cursor is displayed, but the keyboard is not entered.

I even tried it manually, but just didn't work.

Here is my code:

public class CreateNote extends Activity { EditText titleEdit; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.createnote); titleEdit = (EditText) findViewById(R.id.titleEdit); titleEdit.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { InputMethodManager imm = (InputMethodManager) CreateNote.this .getSystemService(Service.INPUT_METHOD_SERVICE); imm.showSoftInput(titleEdit, 0); } }); } } 

Layout Fragment:

  <FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#989898" > <EditText android:id="@+id/titleEdit" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/edittextdrawale" android:ems="10" android:textColor="#fff" android:textColorHint="#fff" > <requestFocus /> </EditText> </FrameLayout> 

What could be the reason for playing hide and seek on my virtual keyboard? I am testing on a real device, not on an emulator.

+4
source share
4 answers

Try it, it worked for me.

 EditText etHorseName = (EditText) getView().findViewById(R.id.horseName); etHorseName.clearFocus(); 

in onCreate() or wherever you want.

+9
source

Late answer, but here's how to solve it without adding code, just remove this from your XML:

 <requestFocus /> 

I don’t know why the keyboard does not appear when it is installed ... However, it appears if you first lose focus, and then click the edit text. I had a problem on Android 2.3.6, but it worked on 4.1.2, so maybe this was an early bug.

+3
source

This is just the default behavior, you should not do it manually, remove some of the code from your code.

 titleEdit.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { InputMethodManager imm = (InputMethodManager) CreateNote.this .getSystemService(Service.INPUT_METHOD_SERVICE); imm.showSoftInput(titleEdit, 0); } }); 
0
source

Try to hide and show the keyboard with this code:

 InputMethodManager imm = (InputMethodManager) this.getSystemService(Service.INPUT_METHOD_SERVICE); // To show keyboard imm.showSoftInput(titleEdit, 0); // To hide keyboard imm.hideSoftInputFromWindow(titleEdit.getWindowToken(), 0); 
0
source

All Articles