my case is: I have one EditText field that is with disabled focus. Beside EditText field I has two buttons for Input methods. So I want when click first button: to open soft keybord and edit text in EditText field. I try many ways with:
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);
and doesn't work for me. Only way to open soft keyboard is:
toggleSoftInput(InputMethodManager.SHOW_FORCED, 0)
but there is no way to edit info from EditText field.
May you suggest me how to open keyboard and edit text for some EditText when click button. Thanks a lot!
Edited:
So, EditText is not focusable be default. When I click Keyboard button - should be focusable, then show me soft keyboard to enter text and appear in EditText. Other method to insert is A-B-C button which not required keyboard. It will be something like Morse code input - touch and hold A-B-C button :) I'll try suggested example to implement in my case. Thank you guys :)
The design you've described isn't recommended. You're violating the
focusable
attribute's purpose which is not to control whether the user can alter the text in aEditText
component.If you plan to provide an alternative input method because the use case seems to require this (e.g. you allow only a certain set of symbols in the editable text field) then you should probably disable text editing altogether for the time the user isn't allowed to change the value of the field.
Declare your editable field:
notice that its
focusable
attribute is left with the default value. That's ok, we'll handle that later. Declare a button which will start editing process:Now, in your
Activity
declare:And in
onCreate()
do this:I hope the code with all the comments is self-explanatory. Tested on APIs 8 and 17.
For those that uses fragments you can use
InputMethodManager
that way:Full Code:
Thanks guys for your help :) I used all suggestions that you gave me, searched and tested a lot of other scripts and finally my code is working :)
Here is my final code:
It may be useful for someone :) Thank you!
I Have Work this code for open a keybord when button click. Like .
its completed work.
Try this :