0

I'm currently developing a calculator app where I have made a custom keypad and would like to hide the virtual keyboard. I have found solutions where I can hide it, but the cursor also gets hidden. The functionality I want is the same as the com.android.calculator2 app. I have looked at the source code of that but I still can't get it to work.

user3103398
  • 143
  • 9
  • is your 'keypad' a collection of buttons? or have you coded a proper keyboard ? – harveyslash Jul 08 '14 at 16:20
  • @harvey_slash It is a collection of buttons. How do I create a proper keyboard? I don't think the com.android.calculator2 app uses a "proper" keyboard. – user3103398 Jul 08 '14 at 16:23
  • so you can just set clicklisteners to the buttons, right ? – harveyslash Jul 08 '14 at 16:23
  • @harvey_slash my problem isn't getting the keys to work, it's getting the default keyboard to be hidden. (So two keyboard do not show, mine and the default one) – user3103398 Jul 08 '14 at 16:25

1 Answers1

1

I think you are getting it wrong. There is a much easier solution(and a more obvious one).

  1. Make the EditText uneditable.
  2. Bind to the EditText in your code (findViewById)
  3. In your buttons, get the text and add to the current string and then display it.

Eg.

say you pressed the '1' button.

in your one.setOnclickListener(), do this:

String S=EditText.getText()+"1"; 
EditText.setText(s);

Edit:

If you just want to hide the keyboard while keeping the cursor, try this code:

EditText editText = (EditText)findViewById(R.id.edit_text);
editText.setOnTouchListener(new OnTouchListener() {

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        v.onTouchEvent(event);
        InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null) {
            imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
        }                
        return true;
    }
});
harveyslash
  • 5,906
  • 12
  • 58
  • 111