EditText in custom dialog in Android cannot eject IME solution

Source: Internet
Author: User

1. Resolve Unable to eject input method:

Before the show () method call, add an empty EditText with Dialog.setview (new EditText), because the custom Alertdialog has the layout we specify, so setting this does not affect our functionality, So you can pop up the input method ...

2. The input method can be popped, but in order to enhance the user experience, when the dialog contains edittext should be, in the display dialog the same time automatically eject the keyboard:
(1) The following methods can be added to the custom dialog:
public void Showkeyboard () {if (edittext!=null) {//set can get focus edittext.setfocusable (TRUE); Edittext.setfocusableintouchmode (TRUE);//request to get focus edittext.requestfocus ();//Call system input Inputmethodmanager InputManager = (Inputmethodmanager) edittext.getcontext (). Getsystemservice (Context.input_method_service); Inputmanager.showsoftinput (editText, 0);}}
where EditText is the view of the input box in the custom dialog
(2) after Dialog.show (), call this method to display the IME, because in the call May dialog interface is not loaded complete, editText may also be empty, so need to add a delay task, delay display:
Dialog.show (); Timer timer = new timer (), Timer.schedule (new TimerTask () {@Overridepublic void run () {Dialog.showkeyboard ();}}, 200);










EditText in custom dialog in Android cannot eject IME solution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.