Cong Binh
Cong Binh

Reputation: 77

How to set action for button on this custom dialog?

I make a custom Dialog like as :

public class CustomDialog extends Dialog {
     public CustomDialog(String s) {
    super(s, new String[] {"View","Cancel"}, new int [] {1,2}, 1,         Bitmap.getPredefinedBitmap(Bitmap.EXCLAMATION), Manager.FOCUSABLE);

    }

How can I set action for "View button" and " Cancel button " ? I searched and not found what I have to do . Please help me !

Upvotes: 0

Views: 626

Answers (2)

jprofitt
jprofitt

Reputation: 10964

Attach a DialogClosedListener to your CustomDialog using Dialog.setDialogClosedListener(). When someone clicks either of the buttons, the DialogClosedListener.dialogClosed() method will be called and the button index will be passed as the choice parameter.

Upvotes: 1

Nilanchala
Nilanchala

Reputation: 5941

Check out this code.. this might help you..

import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.container.HorizontalFieldManager;

public class CustomAlertDialog extends Dialog {


    public CustomAlertDialog() {
        super("Your Custom message for Dialoug" , null, null, Dialog.DISCARD, null, Dialog.VERTICAL_SCROLL);

        HorizontalFieldManager hfm = new HorizontalFieldManager();

        ButtonField view = null;

        view = new ButtonField("view") {
            protected boolean navigationClick(int status, int time) {
            // do what ever you want
            return true;
            }

            protected boolean keyChar(char key, int status, int time) {
            // do what ever you want
            return true;
            }
        };

        ButtonField cancel = null;
        cancel = new ButtonField("Cancel") {
            protected boolean navigationClick(int status, int time) {
            // do what ever you want
            return true;
            }

            protected boolean keyChar(char key, int status, int time) {
            // do what ever you want
            return true;
            }
        };
    hfm.add(view);
    hfm.add(cancel);

    this.add(hfm);
    }
}

Upvotes: 0

Related Questions