Input Text into Invisible EditText

560 views Asked by At

My question is on invoking the soft-keyboard in Android.

I am trying out the FingerPaint (API Demos), which is essentially a touch-drawing app. Attempting to give it a touch text-input interface, I added EditText inside the CustomView class, like the following:

private void inputText() {

    EditText newText = new EditText(getContext());  
        //getContext needed as we're in a class extending View, not activity

    newText.setText("Text Text Text");

       //'addView' is deliberately left out for invisibility
       //'requestFocus' also left out

       // Show soft keyboard for the user to enter the value.
    InputMethodManager imm = (InputMethodManager) ConfigKey.context.getSystemService("input_method"); 
    imm.showSoftInput(newText, InputMethodManager.SHOW_IMPLICIT);

    String newTextString = newText.getText().toString();
    System.out.println(newTextString);
  }  

The EditText was added alright (as seen from the Logcat, "Text Text Text") but there was just no keyboard to be seen for inputing.

Any way to fix it?

Any thoughts would be appreciated!

0

There are 0 answers