javajavascriptandroidnative-code

How to make Alert, Prompt and confirm dialog of javascript in java Android


I want to make a confirm function in java just like a alert in javascript.

Example javascript code: var a = prompt("");

In java i have a function that returns a string with a dialog box input;

      public static boolean log ;
      public String value;
        public String androidPrompt(){
              log = true;             
              showMyDialog();
              while(log){
              }
              return value;

        }


       public void showMyDialog(){
          log= false;
           value = //inputed value from dialog; 
       }

But my application don't respond. What should i do. I want to pause androidPrompt() while showMyDialog() is not done. and when showMyDialog() is done androidPrompt() function will resume and return the value


Solution

  • Example javascript code: var a = prompt("");

    Android does not support that sort of blocking UI call. Instead, use listeners to notify something within your app when the user has accepted the dialog (e.g., pressed the OK button).