purplewind
purplewind

Reputation: 351

Dialog box does not appear after method call

I am trying to build a dialog box in android but it does not appear after calling the method.

This is how I declare the method:

public Dialog onCreateDialog() {
    // Use the Builder class for convenient dialog construction
    AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
    builder.setMessage("testing")
            .setPositiveButton("COPY TO", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    // do something
                }
            })
            .setNegativeButton("MOVE TO", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    //do something
                }
            });
    // Create the AlertDialog object and return it
    return builder.create();
}

This is how I call the method:

for (int i = 0; i < lvMain.getChildCount(); i++) {
            LinearLayout itemLayout = (LinearLayout) lvMain.getChildAt(i);
            final CheckBox cb = (CheckBox) itemLayout.findViewById(R.id.cbBox);
            cb.setVisibility(View.VISIBLE);
            cb.setChecked(true);
            onCreateDialog();
        }

Any idea why it won't work ?

Upvotes: 0

Views: 45

Answers (1)

rib
rib

Reputation: 200

I think you forgot .show();

    AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
    builder.setMessage("testing")
            .setPositiveButton("COPY TO", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    // do something
                }
            })
            .setNegativeButton("MOVE TO", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    //do something
                }
            }).show();
}

Upvotes: 1

Related Questions