2

I am trying to make an android application for Tablet. I need to display keyboard above all my activities by default and i don't need to hide the keyboard when user presses back key. Any idea to make it work???

EDIT: Solved by using a custom EditText

    public class CustomEdit extends EditText {

public CustomEdit(Context context, AttributeSet attrs) {
    super(context, attrs);
    // TODO Auto-generated constructor stub
}
@Override
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
    // TODO Auto-generated method stub
    Log.e("Log", "onKeyPreIme");
    return true;
    //return super.onKeyPreIme(keyCode, event);
}

}

Android: How to make the keypad always visible?

Community
  • 1
  • 1
Favas Kv
  • 2,961
  • 2
  • 28
  • 38

3 Answers3

2
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);

And also add this to catch the backButton being pressed and do nothing on it.

@Override
    public void onBackPressed() {
        // do nothing
        return;

    }

Also,

mEditText.setOnKeyListener(new View.OnKeyListener() {
            public boolean onKey(View v, int keyCode, KeyEvent event) {


            if (keyCode == KeyEvent.KEYCODE_BACK) 
                     // again do nothing

              return false;
                  } };

NOTE : Only adding android:windowSoftInputMode="stateAlwaysVisible" will show the keyboard initially but can be dismissed by pressing the BackButton if you don't override the backButton.

Swayam
  • 16,294
  • 14
  • 64
  • 102
2

you could use this in your manifest, android:windowSoftInputMode="stateAlwaysVisible" for all you activity.

XepterX
  • 1,017
  • 6
  • 16
1

i've implemented this in one of my application. u need following code.

// getting InputMethodManager system service which will handle aur
        // keyboard event
        InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);

        // restartInput method will restart the current view with its updated 
        // content. here medtName is a EditText
        imm.restartInput(medtName);

        // toggleSoftInput will responsible for showing or hiding device
        // keyboard.
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
NaserShaikh
  • 1,576
  • 2
  • 23
  • 39