3

I am writing a calculator for Android, for inputting expression I use EditText. As I create my buttons - I do not need a software keyboard, but I want to change the cursor position, text selection, copy, paste. In a word - everything as it is, only the virtual keyboard is not displayed. In version 2.3 I could write:

EditText.setInputType (InputType.TYPE_NULL);

and it worked perfectly. In version 4 of the cursor is not displayed, the menu does not work, etc. Tried a bunch of ways - you can not move the cursor, the keyboard is displayed, and it was never really explained.

InputMethodManager imm = (InputMethodManager)getSystemService(
    Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0); //cursor not showing
------------------------------------------------------------------------
getWindow().setSoftInputMode(
    WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); //not working

I want to make it as in Panecal, MobiCalc Free, Scientific Calculator. I would be happy with any helpful suggestions on this. P.S. Sorry for my English.

Abdul Rahman
  • 2,097
  • 4
  • 28
  • 36

2 Answers2

2

From the link posted below, here is an example to consume on touch for an Edittext

editText_input_field.setOnTouchListener(otl);

private OnTouchListener otl = new OnTouchListener() {
    public boolean onTouch (View v, MotionEvent event) {
            return true; // the listener has consumed the event
    }
 };

Here is another example from the same website. This claims to work but seems like a bad idea since your EditBox is NULL it will be no longer an editor:

MyEditor.setOnTouchListener(new OnTouchListener(){ 
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        int inType = MyEditor.getInputType(); // backup the input type
        MyEditor.setInputType(InputType.TYPE_NULL); // disable soft input
        MyEditor.onTouchEvent(event); // call native handler
        MyEditor.setInputType(inType); // restore input type
        return true; // consume touch even
   }
});

Hope this points you in the right direction

The above answer was taken from - how to block virtual keyboard while clicking on edittext in android?

This might work too getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

Community
  • 1
  • 1
jcw
  • 5,132
  • 7
  • 45
  • 54
  • in first case keyboard is hide, cursor is blinking, but I can`t move it; second case is the same but cursor set at start of expression; third case absolutely nothing on effect. Thank you for trying to help. – user1814546 Nov 10 '12 at 14:38
  • If you Google how to stop the soft keyboard from comming up you will get more results – jcw Nov 10 '12 at 14:41
0

The exact solution to this is by setting the flag textIsSelectable in EditText to true. This will retain the cursor and you'll be able to utilise the basic select/copy/cut/paste,etc functions.You can set it in your xml layout like this:

You can set it programmatically like this:

EditText edit_text = (EditText) findViewById(R.id.editText);
edit_text.setTextIsSelectable(true);

Or in your XML Layout :

<EditText
    ...
    android:textIsSelectable="true"
/>

For anyone using API 10 and below, hack is provided here : https://stackoverflow.com/a/20173020/7550472

Community
  • 1
  • 1
Kaushik NP
  • 6,733
  • 9
  • 31
  • 60