<bdo id='AOmIm'></bdo><ul id='AOmIm'></ul>
      <tfoot id='AOmIm'></tfoot>

        <small id='AOmIm'></small><noframes id='AOmIm'>

      1. <i id='AOmIm'><tr id='AOmIm'><dt id='AOmIm'><q id='AOmIm'><span id='AOmIm'><b id='AOmIm'><form id='AOmIm'><ins id='AOmIm'></ins><ul id='AOmIm'></ul><sub id='AOmIm'></sub></form><legend id='AOmIm'></legend><bdo id='AOmIm'><pre id='AOmIm'><center id='AOmIm'></center></pre></bdo></b><th id='AOmIm'></th></span></q></dt></tr></i><div id='AOmIm'><tfoot id='AOmIm'></tfoot><dl id='AOmIm'><fieldset id='AOmIm'></fieldset></dl></div>
        <legend id='AOmIm'><style id='AOmIm'><dir id='AOmIm'><q id='AOmIm'></q></dir></style></legend>

        Android:等待来自对话框的用户输入?

        Android: wait on user input from dialog?(Android:等待来自对话框的用户输入?)

            • <legend id='IAZsP'><style id='IAZsP'><dir id='IAZsP'><q id='IAZsP'></q></dir></style></legend>
              <tfoot id='IAZsP'></tfoot>

                <bdo id='IAZsP'></bdo><ul id='IAZsP'></ul>

                  <tbody id='IAZsP'></tbody>

                1. <i id='IAZsP'><tr id='IAZsP'><dt id='IAZsP'><q id='IAZsP'><span id='IAZsP'><b id='IAZsP'><form id='IAZsP'><ins id='IAZsP'></ins><ul id='IAZsP'></ul><sub id='IAZsP'></sub></form><legend id='IAZsP'></legend><bdo id='IAZsP'><pre id='IAZsP'><center id='IAZsP'></center></pre></bdo></b><th id='IAZsP'></th></span></q></dt></tr></i><div id='IAZsP'><tfoot id='IAZsP'></tfoot><dl id='IAZsP'><fieldset id='IAZsP'></fieldset></dl></div>

                  <small id='IAZsP'></small><noframes id='IAZsP'>

                  本文介绍了Android:等待来自对话框的用户输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我想实现一个显示对话框的方法,等待对话框关闭,然后根据对话框内容返回结果.这可能吗?

                  I would like to implement a method that displays a dialog, waits until the dialog is dismissed, and then returns a result depending on the dialog contents. Is this possible?

                  public String getUserInput()
                  {
                      //do something to show dialog
                      String input = //get input from dialog
                      return input;
                  }
                  

                  我实际上是在尝试实现一个具有方法public String getUserInput()"的接口,其中返回的字符串必须通过对话框检索.这在java中很容易做到,在android中似乎不可能?

                  I am actually trying to implement an interface which has method "public String getUserInput()", where the returned String must be retrieved via dialog. This is easily done in java, seems impossible in android?

                  根据评论中的要求发布一些示例代码

                  Posting some sample code as requested in comment

                  getInput() 必须从后台线程调用(我从AsynchTask 调用它).getInput() 显示一个对话框并调用等待.当在对话框上按下 ok 按钮时,对话框将用户输入设置在成员变量中并调用 notify.当调用 notify 时,getInput() 继续并返回成员变量.

                  getInput() must be called from a background thread (I call it from an AsynchTask). getInput() displays a dialog and calls wait. When the ok button is pressed on the dialog, the dialog sets the user input in a member variable and calls notify. When notify is called, getInput() continues and returns the member variable.

                  String m_Input;
                  
                  public synchronized String getInput()
                  {
                      runOnUiThread(new Runnable() 
                      {
                          @Override
                          public void run() 
                          {
                              AlertDialog.Builder alert = new AlertDialog.Builder(context);
                              //customize alert dialog to allow desired input
                              alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                              public void onClick(DialogInterface dialog, int whichButton)
                              {
                                            m_Input = alert.getCustomInput();
                                            notify();
                              }
                          });
                          alert.show();   
                          }
                      });
                  
                      try 
                      {
                           wait();
                      } 
                      catch (InterruptedException e) 
                      {
                      }
                  
                      return m_Input;
                  }
                  

                  推荐答案

                  感谢所有反馈,我能够使用后台线程以及 wait() 和 notify() 来解决这个问题.我承认这不是给定范例的最佳想法,但有必要符合我正在使用的库.

                  Thanks for all the feedback, I was able to solve this using a background thread along with a wait() and notify(). I recognize this isn't the greatest idea for the given paradigm, but it was necessary to conform to a library that I am working with.

                  这篇关于Android:等待来自对话框的用户输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How To Create a Rotating Wheel Control?(如何创建转轮控件?)
                  How to avoid restarting activity when orientation changes on Android(如何在 Android 上的方向更改时避免重新启动活动)
                  iOS: How to run a function after Device has Rotated (Swift)(iOS:设备旋转后如何运行函数(Swift))
                  iOS 8 Rotation Methods Deprecation - Backwards Compatibility(iOS 8 旋转方法弃用 - 向后兼容性)
                  Screen orientation lock(屏幕方向锁定)
                  Strange behavior with android orientation sensor(android方向传感器的奇怪行为)
                    <tfoot id='jiBhP'></tfoot>
                        • <bdo id='jiBhP'></bdo><ul id='jiBhP'></ul>

                            <tbody id='jiBhP'></tbody>

                          <small id='jiBhP'></small><noframes id='jiBhP'>

                            <legend id='jiBhP'><style id='jiBhP'><dir id='jiBhP'><q id='jiBhP'></q></dir></style></legend>
                            <i id='jiBhP'><tr id='jiBhP'><dt id='jiBhP'><q id='jiBhP'><span id='jiBhP'><b id='jiBhP'><form id='jiBhP'><ins id='jiBhP'></ins><ul id='jiBhP'></ul><sub id='jiBhP'></sub></form><legend id='jiBhP'></legend><bdo id='jiBhP'><pre id='jiBhP'><center id='jiBhP'></center></pre></bdo></b><th id='jiBhP'></th></span></q></dt></tr></i><div id='jiBhP'><tfoot id='jiBhP'></tfoot><dl id='jiBhP'><fieldset id='jiBhP'></fieldset></dl></div>