It would be a shame if you could not get a result back from a dialog.
Here's one example of how to do it:

AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle(title);
alert.setMessage(message);

// You can set an EditText view to get user input besides
// which button was pressed.
final EditText input = new EditText(this);
alert.setView(input);

alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
  String value = input.getText();
  // Do something with value!
  }
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener
() {
  public void onClick(DialogInterface dialog, int whichButton) {
    // Canceled.
  }
});

alert.show();



I got it from here: http://www.damonkohler.com/2009/02/android-recipes.html



Yusuf Saib
Android
·T· · ·Mobile· stick together
The views, opinions and statements in this email are those of the
author solely in their individual capacity, and do not necessarily
represent those of T-Mobile USA, Inc.





On Aug 10, 12:12 am, chaoz1336 <[email protected]> wrote:
> Hi Guys,
>
> I got the following prob:
> -I have to implement an interface
> -in most methods its like "show dialog and get the selected result"
> -afaik in android there is no way to wait for such a result
>
> so... that's the base;
>
> [syntax="java"]public int showDlg()
>     {
>         int iSelectedChoice = -1;
>
>         //show Dlg
>
>         //wait for Dlg to be finished (ok or cancel is clicked)
>
>         return iSelectedChoice;     //return selected choice
>     }[/syntax]
>
> and my current implementation:
>
> [syntax="java"]public int AskQuestion(String[] choices, String
> strQuestion, int preSelect)
>     {
>         Dialog oDlg = null;
>         Builder oBuilder = new AlertDialog.Builder(this);
>         oBuilder.setIcon(R.drawable.cortado_icon);
>         oBuilder.setTitle("Question");
>         oBuilder.setSingleChoiceItems(choices, 0, this);
>         oBuilder.setPositiveButton("ok", this);
>         oBuilder.setNegativeButton("cancel", this);
>
>         oDlg = oBuilder.create();
>         oDlg.show();
>
>         while(m_fBool == false) //m_fBool is set true when a button is
> clicked (in the onClicklistener)
>         {
>             try
>             {
>                 Thread.sleep(100);
>             }
>             catch (InterruptedException e)
>             {
>                 e.printStackTrace();
>             }
>         }
>
>         return m_iResult;
>     }[/syntax]
>
> In my implementation I can't see the Dialog anyway =(
> Please help me, its urgent!!!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to