Jim
Jim

Reputation: 9234

AlertDialog doesn't work

@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?

Upvotes: 0

Views: 4033

Answers (3)

qiuping345
qiuping345

Reputation: 148

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

Upvotes: 1

Hakan Ozbay
Hakan Ozbay

Reputation: 4719

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.

Upvotes: 3

dave.c
dave.c

Reputation: 10908

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:

Upvotes: 2

Related Questions