2012-04-27 79 views

回答

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

}  

} 

現在,在下面的方式調用此對話框......

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

輸出將是:

enter image description here

獲取的確定事件和取消按鈕。

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

希望幫助全..

+0

感謝u.but我有一個關於this.i有些疑惑想ok.how我必須編寫 – user1213202 2012-04-27 10:18:07

+0

@ sandhya.M我有編輯來執行按鈕一些動作現在發佈你可以獲得行動事件。 – 2012-04-27 10:30:39

0

創建popupScreen並在此屏幕中可以添加單選按鈕和複選框。

public class Custom_Popup extends PopupScreen { 

public Custom_Popup() { 
    // TODO Auto-generated constructor stub 
    super(new VerticalFieldManager(Manager.VERTICAL_SCROLL), 
Field.NON_FOCUSABLE | Field.USE_ALL_WIDTH); 



} 

} 
0

在您的活動中,按此屏幕。

UiApplication.getUiApplication().pushScreen(new MyPopup()); 


public class MyPopup extends PopupScreen{ 
public MyPopup() { 
    super(new VerticalFieldManager(), Field.FOCUSABLE); 
    add();//add checkbox , radio buttons here. 
} 
相關問題