【发布时间】:2014-05-05 02:43:46
【问题描述】:
我想提示用户使用对话框在我的 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();
但是这个 给我:
android.view.WindowManager$BadTokenException: 无法添加窗口 -- 令牌 null 不适用于应用程序
我的代码是否有任何问题,似乎在对话框中传递了一个空参数,但我无法找出问题所在。
【问题讨论】:
-
String value = input.getText().toString();
标签: android