Saturday, June 25, 2011

[android-developers] Can't show AlertDialog

I must be missing something obvious, but just can't see it. Here's
part of my Activity code:

public static AlertDialog func(final Activity activity) {
AlertDialog.Builder d = new AlertDialog.Builder(activity);
d.setTitle("title");
d.setMessage("message");
d.setPositiveButton("yes", new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which)
{}
});
d.setNegativeButton("no", new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which)
{}
});
return d.show(); // <-- nothing shows!
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.dofunc:
dlg = func(this);
if (dlg != null) {
Log.d("App", dlg.toString()); // <-- shows up in log
}
return true;
default:
return super.onOptionsItemSelected(item);
}
}

This virtually identical to the example in "Beginning Android 2",
except I've put the dialog creation into its own function. There's no
exceptions, no relevant log messages apart from my own. Any help
greatly appreciated!

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment