关于 ComboBox 和 Radio

最近用到了 ComboBox 和 Radio  在网上找了写例子看了下,但是出不了效果,后来自己研究了一下,终于出效果了,现在记录一下:

 

ComboBox ;

 

ListStore<BaseModel> merchantStore = new ListStore<BaseModel>();
  merchantStore.add(getType());
  ComboBox<BaseModel> merchant = new ComboBox<BaseModel>();
  merchant.setFieldLabel("商户:");

  merchant.setDisplayField("type");
  merchant.setEmptyText("==Select=="); 
  merchant.setStore(merchantStore);
  merchant.setTypeAhead(true);  
  merchant.setTriggerAction(TriggerAction.ALL);

  formPanel.add(merchant, new FormData("100%"));

 

 private List<BaseModel> getType() {
  List<BaseModel> list = new ArrayList<BaseModel>();
  list = new ArrayList<BaseModel>();
  BaseModel bm = new BaseModel();
  bm.set("type", "猫类");
  bm.set("key",1);
  list.add(bm);
  bm = new BaseModel();
  bm.set("type", "狗类");
  bm.set("key",2);
  list.add(bm);
  bm = new BaseModel();
  bm.set("type", "鸟类");
  bm.set("key",3);
  list.add(bm);
  bm = new BaseModel();
  bm.set("type", "其他");
  bm.set("key",4);
  list.add(bm);
  return list;
 }

 

取值:

types.addListener(Events.Change, new Listener<ComponentEvent>(){
   public void handleEvent(ComponentEvent be) {
    ComboBox<BaseModel> selectBox = (ComboBox) be.getComponent();  
    type = selectBox.getValue().get("type"); 
    }
  });

 

Radio  :

final RadioGroup group = new RadioGroup();
  group.setFieldLabel("宠物性别");
  Radio first = new Radio();
  first.setData("key", 1);
  first.setBoxLabel("雄性");
  first.setValue(true);
  group.add(first);
  Radio second = new Radio();
  second.setData("key", 2);
  second.setBoxLabel("雌性");
  group.add(second);
  formPanel.add(group, new FormData("100%")); 

 

取值;

group.addListener(Events.Change, new Listener<BaseEvent>() {  
         public void handleEvent(BaseEvent be) {  
             RadioGroup selectedRadioGroup = (RadioGroup) ((FieldEvent) be).getComponent();
             String haha = selectedRadioGroup.getValue().getData("key")+"";
            if(haha.equals("1")){
              sex = "雄性";
             }
             if(haha.equals("2")){
              sex = "雌性";
             }
           }  
   });

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值