Search code examples
androidandroid-edittextkeyboard

When click in numeric keyboard close keyboard and put number


I am trying to put the number clicked and close keyboard because just need one number and I don't know how to do it!

< Edited >

I have to put scores for sets, like tennis, and its up to 7 almost, then with one key its enough, I have numeric keyboard, until here perfect, but I would like to click one number and close keyboard with number in editText field.


Solution

  • To Close keyboard:

    // Check if no view has focus:
    View view = this.getCurrentFocus();
    if (view != null) {  
        InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
    

    And to set the number typed you use the editText´s Listerners