开发者

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 ha开发者_JS百科ve to do . Please help me !


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.


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);
    }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜