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.
Asked
Active
Viewed 145 times
0
-
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 Answers
1
I think you are getting it wrong. There is a much easier solution(and a more obvious one).
- Make the EditText uneditable.
- Bind to the EditText in your code (findViewById)
- 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
-
I think you're misunderstanding. I still want the cursor to show up in the EditText so that you can change the position of the input. – user3103398 Jul 08 '14 at 16:27
-
i have edited my answer. It should make the edittext behave as you want it to. see it – harveyslash Jul 08 '14 at 16:39
-
Thanks! That worked, but when long pressing, the keyboard comes up and goes right back down. Can that be fixed? – user3103398 Jul 08 '14 at 16:49
-