大家好,我正在通過單擊按鈕在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之間的區別? –