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: [Java]View Plain Copy  
  1. Public void Showkeyboard () {
  2. if (edittext!=null) {
  3. //Set to get focus
  4. Edittext.setfocusable (true);
  5. Edittext.setfocusableintouchmode (true);
  6. //Request for Focus
  7. Edittext.requestfocus ();
  8. //Call system input
  9. Inputmethodmanager InputManager = (inputmethodmanager) editText
  10. . GetContext (). Getsystemservice (Context.input_method_service);
  11. Inputmanager.showsoftinput (EditText, 0);
  12. }
  13. }
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: [Java]View Plain Copy  
    1. Dialog.show ();
    2. Timer timer = new timer ();
    3. Timer.schedule (new TimerTask () {
    4. @Override
    5. public Void Run () {
    6. Dialog.showkeyboard ();
    7. }
    8. }, 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.