在listView的onItemClick函数中显示一个AlertDialog,出现如下错误
08-07 21:26:43.506: ERROR/AndroidRuntime(9390): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
后google解决。
原来代码中显示语句如下
AlertDialog imageDialog = new AlertDialog.Builder(context).setTitle("状态操作").setItems(items, listener).create(); imageDialog.show();
其中context为在OnCreate中
context = getApplicationContext();
得到
异常原因:AlertDialog创建语句
public AlertDialog.Builder (Context context)
中,不能使用getApplicationContext()得到的context,而必须使用Activity,所以解决如下
解决方法:语句修改为
AlertDialog imageDialog = new AlertDialog.Builder(Activity.this).setTitle("状态操作").setItems(items, listener).create(); imageDialog.show();
其中的Activity为当前Activity的名称
参考:
http://blog.csdn.net/yimo29/article/details/6004782
相关推荐
alertDialog,android alertDialog大全
AlertDialog 各种各样的对话框和结合popupwindow使用
android 显示 AlterDialog
使用自定义布点局文件,显示AlertDialog,用作信息提示,确定按钮点击事件
Android AlertDialog对话框 自定义实现遮罩层
android自定义AlertDialog,例如支付页面,先弹出自定义AlertDialog询问是否愿意支付,确定则弹出另外一个自定义AlertDialog,选择支付方式,android自定义AlertDialog,android自定义AlertDialog,android自定义...
android AlertDialog使用例程 一个在安卓平台上开发使用AlertDialog的例子 很实用很全哦
AlertDialog的各种用法,包含简单、复杂、列表、自定义、日期时间、进度条等的对话框
警告框AlertDialog,实现点击弹出警告框,适合初学者下载学习
自定义AlertDialog,颜色什么的自己都可以随意修改,,简单调用即可
1、从Activity的TextView中获取字符串设置到AlertDialog的TextView和EditText中 2、将AlertDialog的EditText中的值设置到Activity的TextView中 新手在自定义AlertDialog上的疑问笔者猜测主要有两个: 1、自定义的...
Android入门第九篇之AlertDialog.docx
android 使用alertdialog创建自定义对话框
比较漂亮的自定义AlertDialog。
自定义AlertDialog布局
提示框多种模式.... alertdialog