Grid 如何在gxt中的网格上添加单选按钮

Grid 如何在gxt中的网格上添加单选按钮,grid,radio,gxt,Grid,Radio,Gxt,在我的应用程序中,我有一个包含一些行的网格 在每一行中,我想放置一个单选按钮,并且在网格中只能选择一个单选按钮(每一行有一个单选按钮) 为此,我尝试添加GridCellRenderer并使用以下代码返回单选按钮: GridCellRenderer<ModelData> button = new GridCellRenderer<ModelData>() { @Override public Object render(ModelData model

在我的应用程序中,我有一个包含一些行的网格

在每一行中,我想放置一个单选按钮,并且在网格中只能选择一个单选按钮(每一行有一个单选按钮)

为此,我尝试添加GridCellRenderer并使用以下代码返回单选按钮:

GridCellRenderer<ModelData> button = new GridCellRenderer<ModelData>() {    
    @Override
    public Object render(ModelData model, String property,
            ColumnData config, final int rowIndex, int colIndex,
            ListStore<MonitorModel> store, Grid<MonitorModel> grid) {
        // TODO Auto-generated method stub
        final RadioGroup radioGroup = new RadioGroup();  

        for(int i=0; i<store.getCount(); i++){
            radio = new Radio();
            radio.setBoxLabel("radio"+rowIndex);     

            if(radio.getBoxLabel().equals("radio0")&& radio.getValue()== false){
                radio.setValue(true);   
                //isFirstTime = true;
            }
            radioGroup.addListener(Events.Change, new Listener<FieldEvent>() {
                public void handleEvent(FieldEvent fe) {                    
                    if (((Boolean)fe.getValue()) == true) {                     
                        radio.setValue(true);   
                    }
                }
            });         

        }       
        radioGroup.add(radio); 
        return radioGroup; 
    }         
};
GridCellRenderer按钮=新建GridCellRenderer(){
@凌驾
公共对象呈现(ModelData模型、字符串属性、,
ColumnData配置,最终整数行索引,整数索引,
列表存储(网格){
//TODO自动生成的方法存根
最终射线组射线组=新射线组();
对于(int i=0;i您应该定义

final RadioGroup radioGroup = new RadioGroup();
作为类字段,但不在“render”方法中。类似如下:

GridCellRenderer<ModelData> button = new GridCellRenderer<ModelData>() {

    final RadioGroup radioGroup = new RadioGroup();  

    @Override
    public Object render(ModelData model, String property,
            ColumnData config, final int rowIndex, int colIndex,
            ListStore<MonitorModel> store, Grid<MonitorModel> grid) {

        for(int i=0; i<store.getCount(); i++){
            radio = new Radio();
            radio.setBoxLabel("radio"+rowIndex);     
    ......
GridCellRenderer按钮=新建GridCellRenderer(){
最终射线组射线组=新射线组();
@凌驾
公共对象呈现(ModelData模型、字符串属性、,
ColumnData配置,最终整数行索引,整数索引,
列表存储(网格){

对于(inti=0;i我得到了答案,我使用了以下方法

GridCellRenderer<ModelClass> button = new GridCellRenderer<ModelClass>() {    
        @Override
        public Object render(final ModelClass model, String property,
                ColumnData config, final int rowIndex, int colIndex,
                final ListStore<ModelClass> store, Grid<ModelClass> grid) {     
            Radio radio = new Radio(); 
            for(int i=0; i< store.getCount(); i++){
                radio = new Radio();
                radio.setName("Radio"+ i);
                radio.setHeight(16);

                if (model.get("checked").equals(Boolean.TRUE)) { 
                    radio.setValue(true); 
                } 
                else { 
                    radio.setValue(false); 
                } 
            } 
            radio.addListener(Events.OnClick, new Listener<FieldEvent>() {              
                @Override
                public void handleEvent(FieldEvent be) {                    
                    // TODO Auto-generated method stub
                    // Something....
                }
            });
            return radio; 
        } 

    };
GridCellRenderer按钮=新建GridCellRenderer(){
@凌驾
公共对象呈现(最终模型类模型、字符串属性、,
ColumnData配置,最终整数行索引,整数索引,
最终列表存储,网格网格){
收音机=新收音机();
for(int i=0;i
它起作用了