I created EditText by drawing it on canvas so I have problem on making the keyboard appear when clicked and to make the EditText receive input. After some searching, I found out that I can use InputMethodManager to make the keyboard appear to give inputs for EditText.
Unfortunately, EditText does not receive any character inputs from anything pressed on the soft keyboard.
And I need to use imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
because when I used imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
the soft keyboard did not appear at all when EditText is pressed.
Code:
if((int)event.getX() > 50 && event.getX()<400 && event.getY() > 50 && event.getY() < 200){
editText.setFocusable(true);
editText.setFocusableInTouchMode(true);
editText.requestFocus();
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
How to solve this? Any working solution is welcomed. Thanks!
This should work fine.
EditText edit = (EditText) view.findViewById(R.id.passwordtextvalue);
edit.setOnKeyListener(this);
InputMethodManager imgr = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imgr.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
edit.requestFocus();
I have this in my app, and its working fine for edit text when I have the soft keyboard
Try this
EditText yourEditText= (EditText) findViewById(R.id.yourEditText);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.