单击单选按钮上的编辑字段单击黑莓

时间:2011-12-05 04:17:32

标签: blackberry

我有两个Radiobutton并在一个单选按钮上单击我想要隐藏编辑字段,所以请任何人都可以帮助我。 谢谢,提前。

2 个答案:

答案 0 :(得分:0)

试试这个会起作用

package com.hb;



import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.component.RadioButtonField;
import net.rim.device.api.ui.component.RadioButtonGroup;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;

public class Startup extends UiApplication{

    public static void main(String[] args) {
        Startup start=new Startup();
        start.enterEventDispatcher();
    }
    public Startup() {
        pushScreen(new screen());
    }   
}

class screen extends MainScreen implements FieldChangeListener
{

    RadioButtonField field1,field2;
    private EditField edit1;
    private VerticalFieldManager edit_mgr=null;
    public screen() {
        HorizontalFieldManager hr=new HorizontalFieldManager();
        RadioButtonGroup g=new RadioButtonGroup();
        field1=new RadioButtonField("edit", g,true);
        field1.setChangeListener(this);
        hr.add(field1);

        field2=new RadioButtonField("no edit", g,false);
        field2.setChangeListener(this);
        hr.add(field2);
        add(hr);


        edit_mgr=new VerticalFieldManager();
        edit1=new EditField();
        edit1.setEditable(true);
        edit_mgr.add(edit1);
        add(edit_mgr);
    }
    public void fieldChanged(Field field, int context) {
        if(field==field1){
            synchronized (UiApplication.getEventLock()) {
                edit1.setEditable(true);

            }
        }else if(field==field2){
            synchronized (UiApplication.getEventLock()) {
                edit1.setEditable(false);
            }
        }

    }

}   

答案 1 :(得分:0)

也许您可以尝试使用Managers删除和添加字段。尝试:



    package mypackage;

    import net.rim.device.api.ui.Field;
    import net.rim.device.api.ui.FieldChangeListener;

        import net.rim.device.api.ui.component.BasicEditField;
        import net.rim.device.api.ui.component.RadioButtonField;
        import net.rim.device.api.ui.component.RadioButtonGroup;
        import net.rim.device.api.ui.container.MainScreen;
        import net.rim.device.api.ui.container.VerticalFieldManager;

        public final class MyScreen extends MainScreen {

            private BasicEditField bef = new BasicEditField();

            private VerticalFieldManager manager = new VerticalFieldManager();

            private RadioButtonGroup rbg = new RadioButtonGroup();

            public MyScreen() {

                setTitle("Hide Control Demo");

                manager.add(bef);

                add(manager);

                RadioButtonField rbf1 = new RadioButtonField("Option 1", rbg, true);

                RadioButtonField rbf2 = new RadioButtonField("Option 2", rbg, false);

                add(rbf1);

                add(rbf2);

                rbf2.setChangeListener(new FieldChangeListener() {

                    public void fieldChanged(Field field, int context) {

                        if (bef.getManager() != null && rbg.getSelectedIndex() == 1) {

                            manager.delete(bef);

                            System.out.println("Option 2 Selected");
                        }
                    }
                });

            }

        }