大家好,我正在通过单击按钮在android中创建一个警报对话框。我使用XML的onClick属性和调用函数。我的代码是警报对话框不显示
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();}
但是这个代码不显示警告,并给予错误,如
BadTokenException: Unable to add window -- token null is not for an application.
请告诉我,什么是错的这个代码。
尝试:新AlertDialog.Builder(本) – anfy2002us
嘿感谢它的工作,但请你解释一下我是什么这一点,并getAplicationContext之间的区别? –