0

I want to have a soft input keyboard when I click an EditText. I want the keyboard such that it is numeric at beginning, but when user press space, it becomes normal alpha keyboard. I read an answer about this and they say: Use:

 yourEditText.setRawInputType(Configuration.KEYBOARD_QWERTY);

But in some phones, the space button is not present in keyboard. Any idea? Thanks.

Avijit
  • 3,834
  • 4
  • 33
  • 45
berserk
  • 2,690
  • 3
  • 32
  • 63

2 Answers2

0

Add this line in yout edittext in xml:

android:inputType="number" 

Edited:

add these in onTextChanged listener editText:

if((event.getAction()==KeyEvent.ACTION_DOWN)&&(key == KeyEvent.KEYCODE_SPACE)){

   InputMethodManager m = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
  if(m != null){
      m.toggleSoftInput(0, InputMethodManager.SHOW_IMPLICIT);
   } 
}
Avijit
  • 3,834
  • 4
  • 33
  • 45
0

use TextWatcher, when you detect space, change to normal keyboard layout.

onTextChanged(CharSequence s, int start, int before, int count)
{
 String inputText = s.toString();
  // to detect space in String see http://stackoverflow.com/a/4067825/1008278
  if(spaceAvailable)
  {
        changeLayout();
  }

}
VenomVendor
  • 15,064
  • 13
  • 65
  • 96