android prompt user's input using a dialog

前端 未结 2 845
醉酒成梦
醉酒成梦 2020-12-08 16:58

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 AlertDi         


        
相关标签:
2条回答
  • 2020-12-08 17:47

    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.

    0 讨论(0)
  • 2020-12-08 17:56

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

    PromptDialog dlg = new PromptDialog(MainActivity.this, R.string.title, R.string.enter_comment) {
     @Override
     public boolean onOkClicked(String input) {
      // do something
      return true; // true = close dialog
     }
    };
    dlg.show();
    

    See full code => Prompt Dialog for Android

    0 讨论(0)
提交回复
热议问题