我想提示用户使用对话框在我的android应用程序中输入.这是我发现的:
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Title");
alert.setMessage("Message");
// Set an EditText view to get user input
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();
Run Code Online (Sandbox Code Playgroud)
但这给了我:
android.view.WindowManager $ BadTokenException:无法添加窗口 - 令牌null不适用于应用程序
我的代码有什么问题似乎在对话框上传递了一个null参数,但我无法找出问题所在.
android ×1