Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EditText onClick not shows Virtual Keyboard

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.

like image 896
Adam Varhegyi Avatar asked Feb 11 '13 11:02

Adam Varhegyi


People also ask

How do I get the keyboard to show in EditText?

edittext. requestFocus(); -> in code. This will open soft keyboard on which edit-text has request focus as activity appears. This open the keyboard at Activity creation.

How to not show keyboard on EditText Android?

You can force Android to hide the virtual keyboard using the InputMethodManager, calling hideSoftInputFromWindow, passing in the token of the window containing your edit field. This will force the keyboard to be hidden in all situations.


2 Answers

Try with this, it worked for me.

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

in onCreate() or where you want.

like image 175
Sergio Andreotti Avatar answered Oct 10 '22 17:10

Sergio Andreotti


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.

like image 43
Zoneur Avatar answered Oct 10 '22 19:10

Zoneur