1

I have a EditText which can only contain one character. I would like it so that when I tab on the EditText it opens the keyboard (this bit Ive done) and then the text (if any) is selected. This will allow the user to click another letter and because of the selection it will replace the existing letter. After that one letter is pressed I'd like the keyboard to be closed.

Im trying to work out how to hook onto the tap on the EditText as I assume programatically I can set the letter to be selected. Same thing when I input another letter then I can hook into that click and close the keyboard.

The articles Ive found on the keyboard click say that it only works on hardware keyboard where as I need it to work on the soft keyboard.

Can anyone give me any tips and then I can dig to figure this out a bit more.

Thanks

RNJ
  • 14,308
  • 16
  • 73
  • 125

2 Answers2

1

One way to select all text in EditText when user tap on it is set android:selectAllOnFocus="true" attribute for your EditText in your xml file.

For closing soft(virtual) keybord check this post: Close/hide the Android Soft Keyboard

Community
  • 1
  • 1
Rashin
  • 583
  • 4
  • 15
  • Thanks for the answer @Rashin. The selection is just what I was after. I want to close the keyboard after the user has clicked a letter on the keyboard. I havent gone through all of the answer on the linked question (Im at the airport with limited wifi). I check if there is any answer that does this when Im back online properly – RNJ Jul 08 '16 at 18:13
1

I can suggest that you use a TextWatcher, where you can add the desired behavior to close the keyboard when the letter is typed. Combine that with android:selectAllOnFocus="true" as @Rashin said, and it should do the trick!

Vucko
  • 7,000
  • 2
  • 21
  • 42