If i click on my EditText, the virtual keyboard simple not shows up. The cursor is shown, but no keyboard to type on.
I even tried it with manually open but just no works.
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);
}
});
}
}
Snippet of Layout:
<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 of playing hide and seek of my virtual keyboard ? I test on real device, not on emulator.
Try with this, it worked for me.
EditText etHorseName = (EditText) getView().findViewById(R.id.horseName);
etHorseName.clearFocus();
in onCreate()
or where you want.
Late answer but here is how to solve it without adding code, just remove this from your XML:
<requestFocus />
No idea why the keyboard does not show up when this is set... It does show up however if you first loose the focus and then click on the edit text. I had the problem on Android 2.3.6 but it worked on 4.1.2, so maybe it was an early bug.
It is just a default behavior , you not suppose to do it manually, remove below part 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);
}
});
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);
来源:https://stackoverflow.com/questions/14810959/edittext-onclick-not-shows-virtual-keyboard