2011-02-05 39 views
0
@Override 
protected Dialog onCreateDialog(int id) { 
    switch (id) { 
     case IDD_COLOR: 
      return new AlertDialog(this); // The constructor AlertDialog(context) is not visible 
    } 

    return null; 
} 

爲什麼?怎麼了?AlertDialog不起作用

回答

3

不能創建一個AlertDialog因爲它有一個受保護的構造,可以通過使用AlertDialog.Builder使AlertDialog的。

More information關於該主題。

1

請使用AlertDialog.Builder,如:

AlertDialog.Builder builder = new AlertDialog.Builder(a) 
     .setCustomTitle(buildAlertTitle(a, title, 18)) 
     .setMultiChoiceItems(choices, checkedChoices, multiChoiceClickListener) 
     .setPositiveButton(okButtonLabel, okButtonClickListener) 
     .setNegativeButton(cancelButtonLabel, cancelButtonClickListener); 

AlertDialog alert = builder.create(); // create one 

alert.show(); //display it 

欲瞭解更多信息,請使用谷歌的 「Android AlertDialog.Builder樣本」
BR 肖恩