使用一个对话框提示的android用户的输入 [英] android prompt user's input using a dialog

查看:87
本文介绍了使用一个对话框提示的android用户的输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提示用户使用一个对话框,让我输入我的Andr​​oid应用程序。这是我发现:

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);

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();

但这 给我:

but this gives me :

android.view.WindowManager $ BadTokenException:无法添加窗口 - 令牌null不是一个应用程序

android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application

有我的$ C $的任何问题,C中,它似乎是一个空参数传递对话框上,但我无法找出是什么问题。

is there any problem on my code it seems like a null argument is passed on the dialog but I can't find out what is the problem.

推荐答案

当我跑到你的code在一个新的项目,它工作得很好。所以,可能是这个您正在使用

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

  • 是不是一个活动
  • 是不考虑的活性​​,即有可能是一个父活动。如果是一些活动的儿童,使用,而不是本。
  • 的getParent()
  • 为null
  • 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

希望这有助于。

这篇关于使用一个对话框提示的android用户的输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆