Skip to content Skip to sidebar Skip to footer

Android Prompt User's Input Using A Dialog

I would like to prompt the user to give me input in my android application using a dialog. this is what I have found: AlertDialog.Builder alert = new AlertDialog.Builder(this); al

Solution 1:

When I ran your code in a new project, it worked fine. So probably "this" that you are using

  • is not an activity
  • is not the activity in view i.e. there might be a parent activity. If it is the child of some activity, use getParent() instead of "this".
  • is null

Hope this helps.

Solution 2:

I've written a helper class that makes it easy to create a prompt dialog with only a few lines of code.

PromptDialogdlg=newPromptDialog(MainActivity.this, R.string.title, R.string.enter_comment) {
 @OverridepublicbooleanonOkClicked(String input) {
  // do somethingreturntrue; // true = close dialog
 }
};
dlg.show();

See full code => Prompt Dialog for Android

Post a Comment for "Android Prompt User's Input Using A Dialog"