开发者

AlertDialog doesn't work

开发者 https://www.devze.com 2023-02-09 06:13 出处:网络
@Override protected Dialog onCreateDialog(int id) { switch (id) { case 开发者_如何转开发IDD_COLOR:
@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
        case 开发者_如何转开发IDD_COLOR:
            return new AlertDialog(this); // The constructor AlertDialog(context) is not visible
    }

    return null;
}

Why? What's wrong?


You cannot create an AlertDialog as it has a protected constructor, you can make AlertDialog's by using AlertDialog.Builder.

More information on that subject.


The constructor AlertDialog(Context context) is protected, and is only visible to its class, sub-classes and classes within the same package.

See this link for how to create an AlertDialog:

  • Creating an AlertDialog


please use AlertDialog.Builder, like:

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 

For more information, please use Google "android AlertDialog.Builder sample"
BR shawn

0

精彩评论

暂无评论...
验证码 换一张
取 消