警报对话框不显示 [英] Alert dialog is not displaying
本文介绍了警报对话框不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好我正在通过点击按钮创建Android中警告对话框。我用XML和调用函数的OnClick属性。我的code是
公共无效selectPhoneType(查看视图)
{
的String []项目= {家,工作,手机,工作传真,住宅传真,寻呼机,其他,自定义};
AlertDialog.Builder建设者=新AlertDialog.Builder(getApplicationContext());
builder.setTitle(选择标签);
AlertDialog警报= builder.create();
alert.show();}
但这种code未显示警告,并给予错误,如
BadTokenException:无法添加窗口 - 令牌null不是一个应用程序。
请告诉我什么是错这个code。
解决方案
新AlertDialog.Builder(getApplicationContext());
我想这就是问题所在。您是否尝试过:
新AlertDialog.Builder(YourActivityClassName.this);
Hi all i am creating an alert dialog in android by clicking a button. i used onClick property of XML and calling function. my code is
public void selectPhoneType(View view)
{
String [] item = {"Home", "Work", "Mobile", "Work Fax", "Home Fax", "Pager", "Other", "Custom"};
AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
builder.setTitle("Select Label");
AlertDialog alert = builder.create();
alert.show();}
but this code is not showing alert and giving error like
BadTokenException: Unable to add window -- token null is not for an application.
Please tell me what is wrong with this code.
解决方案
new AlertDialog.Builder(getApplicationContext());
I think this is the problem. Have you tried:
new AlertDialog.Builder(YourActivityClassName.this);
这篇关于警报对话框不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文