Consider the following listener class, where I want to remember a
promptValue and return. But after invoking it from a dialog I get the
value as null when I expect it to be "hello"
public class PromptListener
implements android.content.DialogInterface.OnClickListener
{
public String promptValue = null;
public void onClick(DialogInterface v, int buttonId)
{
promptValue="hello";
}
}
Here is how I use this call back with a dialog
public static String Prompt(String message, Context ctx)
{
//load some kind of a view
LayoutInflater li = LayoutInflater.from(ctx);
View view = li.inflate(R.layout.promptdialog, null);
//get a builder and set the view
AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
builder.setTitle("Prompt");
builder.setView(view);
//add buttons and listener
PromptListener pl = new PromptListener(view,ctx);
builder.setPositiveButton("OK", pl);
builder.setNegativeButton("Cancel", pl);
//get the dialog
AlertDialog ad = builder.create();
//show
ad.show();
//How come the following is "null" ???
//when it shoudl be "hello" on a button click
return pl.prompt;
}
The last return I should have a "hello".
DOes the builder copy or cache the listener and its local variables??
Appreciate your help
Satya
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---