Search code examples
dialogblackberryalert

Can we Create alert Dialog With Radiobuttons and Checkboxes in Blackberry


i want to create a alert dialog with radiobuttons for single selection or alert dialog with Checkboxes for Multiselection in blackberry.it is possible in android.but i want in blackberry.i searched in google.but i didn't got any solution.please give any suggestions r usefull links for this problem.


Solution

  • import net.rim.device.api.system.Bitmap;
    import net.rim.device.api.ui.component.CheckboxField;
    import net.rim.device.api.ui.component.Dialog;
    import net.rim.device.api.ui.container.DialogFieldManager;
    
    public class CheckboxInputDialog extends Dialog{
    
      private CheckboxField checkboxEditField;
    
      public CheckboxInputDialog(String choices[],int values[], String label){
        super(label, choices,values,Dialog.OK, Bitmap.getPredefinedBitmap(Bitmap.INFORMATION), Dialog.GLOBAL_STATUS);
    
        checkboxEditField  = new CheckboxField("Lablel",false);
        net.rim.device.api.ui.Manager delegate = getDelegate();
        if( delegate instanceof DialogFieldManager){
            DialogFieldManager dfm = (DialogFieldManager)delegate;
            net.rim.device.api.ui.Manager manager =dfm.getCustomManager();
            if( manager != null ){
                manager.insert(checkboxEditField, 0);
            }
        }
    
     }    
    
    }
    

    Now Call this dialog at following way...

        String choices[] = { "OK", "CANCEL" };
        int values[] = { Dialog.OK, Dialog.CANCEL };
        CheckboxInputDialog d = new CheckboxInputDialog(choices,values,"Dialog Label");
        d.show();
    

    Output will Be:

    enter image description here

    Get Event of OK and Cancel Button.

    String choices[] = { "OK", "CANCEL" };
        int values[] = { Dialog.OK, Dialog.CANCEL };
        final CheckboxInputDialog d = new CheckboxInputDialog(choices, values,"Dialog Label");
        UiApplication.getUiApplication().invokeLater(new Runnable() {
            public void run() {
                int iResponse = d.doModal();
                if (iResponse == 0) {
                    System.out.println("Press Ok");
                }else{
                    System.out.println("Press Cancel");
                }
            }
        });
    

    Hope Help full..