【问题标题】:How to hide controls in blackberry如何在黑莓中隐藏控件
【发布时间】:2011-12-06 10:33:01
【问题描述】:

我在顶部有三个按钮,就像选项卡和三个具有自定义设计的垂直管理器一样。我想在单击按钮时隐藏垂直字段管理器(例如,在 android 中有一个属性 GONE 和 VISIBLE)你可以在我的屏幕上看到。任何人对我的问题有想法请发送。

【问题讨论】:

    标签: android blackberry


    【解决方案1】:

    假设你创建 vfm 为

    vfm=new VerticalFieldManager()
    

    然后你像这样将它添加到屏幕上的另一个经理

    hfm.add(vfm);
    

    您可以删除之前添加的垂直字段管理器

    hfm.delete(vfm);
    

    您也可以通过调用删除管理器中的所有字段

    hfm.deleteAll()
    

    【讨论】:

    • 但我想当我再次按下 btn 时,它是否再次可见这个布局?
    • 是的,它将从经理 hfm 中删除 vfm。如果您愿意,您仍然可以保留对象并将其添加回来
    • 假设你有 vfmanager 来展示 yglf (young ..) 或 yblp。当您单击 YG 时,请执行 vfmanager.deleteAll() 、vfmanager.add(yblpmanager)。其他人也一样
    【解决方案2】:

    这是第一次单击 Button1 时的总类数 蓝色将消失再次单击 Button1 蓝色将显示与 4 个按钮相同的效果 这很容易理解屏幕将如何使其无效和删除它的字段并重新绘制

    package com.hb.screens;
    
    import net.rim.device.api.system.Display;
    import net.rim.device.api.ui.Color;
    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.LabelField;
    import net.rim.device.api.ui.container.HorizontalFieldManager;
    import net.rim.device.api.ui.container.MainScreen;
    import net.rim.device.api.ui.container.VerticalFieldManager;
    import net.rim.device.api.ui.decor.BackgroundFactory;
    
    public class DeleteVert extends MainScreen implements FieldChangeListener{
    
        private CustomButtonField btn1,btn2,btn3,btn4;
        private VerticalFieldManager vert1,vert2,vert3,vert4;
        private boolean flag1=true,flag2=true,flag3=true,flag4=true;
        public DeleteVert() {
            VerticalFieldManager main_mgr=new VerticalFieldManager(){
                protected void sublayout(int maxWidth, int maxHeight) {
    
                    super.sublayout(Display.getWidth(),Display.getHeight());
                    setExtent(Display.getWidth(),Display.getHeight());
                }
            };
    
            HorizontalFieldManager hr_mgr=new HorizontalFieldManager(USE_ALL_WIDTH);
            btn1=new CustomButtonField("BUTTON1", Color.RED);
            btn1.setChangeListener(this);
            hr_mgr.add(btn1);
    
            btn2=new CustomButtonField("BUTTON2", Color.RED);
            btn2.setChangeListener(this);
            hr_mgr.add(btn2);
    
            btn3=new CustomButtonField("BUTTON3", Color.RED);
            btn3.setChangeListener(this);
            hr_mgr.add(btn3);
    
            btn4=new CustomButtonField("BUTTON4", Color.RED);
            btn4.setChangeListener(this);
            hr_mgr.add(btn4);
    
            main_mgr.add(hr_mgr);
    
            vert1=new VerticalFieldManager();
            VerticalFieldManager del_mgr=new VerticalFieldManager(){
                protected void sublayout(int maxWidth, int maxHeight) {
                    super.sublayout(Display.getWidth(), 70);
                    setExtent(Display.getWidth(), 70);
                }
            };
            del_mgr.setBackground(BackgroundFactory.createSolidBackground(Color.BLUE));
            LabelField lbl1=new LabelField("VerticalFieldManager1");
            del_mgr.add(lbl1);
            vert1.add(del_mgr);
            main_mgr.add(vert1);
    
    
            vert2=new VerticalFieldManager();
            VerticalFieldManager del_mgr1=new VerticalFieldManager(){
                protected void sublayout(int maxWidth, int maxHeight) {
                    super.sublayout(Display.getWidth(), 70);
                    setExtent(Display.getWidth(), 70);
                }
            };
            del_mgr1.setBackground(BackgroundFactory.createSolidBackground(Color.GREEN));
            LabelField lbl2=new LabelField("VerticalFieldManager2");
            del_mgr1.add(lbl2);
            vert2.add(del_mgr1);
            main_mgr.add(vert2);
    
            vert3=new VerticalFieldManager();
            VerticalFieldManager del_mgr2=new VerticalFieldManager(){
                protected void sublayout(int maxWidth, int maxHeight) {
                    super.sublayout(Display.getWidth(), 70);
                    setExtent(Display.getWidth(), 70);
                }
            };
            del_mgr2.setBackground(BackgroundFactory.createSolidBackground(Color.RED));
            LabelField lbl3=new LabelField("VerticalFieldManager3");
            del_mgr2.add(lbl3);
            vert3.add(del_mgr2);
            main_mgr.add(vert3);
    
            vert4=new VerticalFieldManager();
            VerticalFieldManager del_mgr3=new VerticalFieldManager(){
                protected void sublayout(int maxWidth, int maxHeight) {
                    super.sublayout(Display.getWidth(), 70);
                    setExtent(Display.getWidth(), 70);
                }
            };
            del_mgr3.setBackground(BackgroundFactory.createSolidBackground(Color.CHOCOLATE));
            LabelField lbl4=new LabelField("VerticalFieldManager41");
            del_mgr3.add(lbl4);
            vert4.add(del_mgr3);
            main_mgr.add(vert4);
    
    
    
            add(main_mgr);
    
    
        }
        public void fieldChanged(Field field, int context) {
            synchronized (UiApplication.getEventLock()) {
                if(field==btn1){
                    if(flag1==true){
                        flag1=false;
                        vert1.deleteAll();
    
                    }else{
                        flag1=true;
                        VerticalFieldManager del_mgr1=new VerticalFieldManager(){
                            protected void sublayout(int maxWidth, int maxHeight) {
                                super.sublayout(Display.getWidth(), 70);
                                setExtent(Display.getWidth(), 70);
                            }
                        };
                        del_mgr1.setBackground(BackgroundFactory.createSolidBackground(Color.BLUE));
                        LabelField lbl1=new LabelField("VerticalFieldManager1");
                        del_mgr1.add(lbl1);
                        vert1.add(del_mgr1);
                    }
                }else if(field==btn2){
                    if(flag2==true){
                        flag2=false;
                        vert2.deleteAll();
    
                    }else{
                        flag2=true;
                        VerticalFieldManager del_mgr2=new VerticalFieldManager(){
                            protected void sublayout(int maxWidth, int maxHeight) {
                                super.sublayout(Display.getWidth(), 70);
                                setExtent(Display.getWidth(), 70);
                            }
                        };
                        del_mgr2.setBackground(BackgroundFactory.createSolidBackground(Color.GREEN));
                        LabelField lbl2=new LabelField("VerticalFieldManager2");
                        del_mgr2.add(lbl2);
                        vert2.add(del_mgr2);
                    }
                }else if(field==btn3){
                    if(flag3==true){
                        flag3=false;
                        vert3.deleteAll();
    
                    }else{
                        flag3=true;
                        VerticalFieldManager del_mgr3=new VerticalFieldManager(){
                            protected void sublayout(int maxWidth, int maxHeight) {
                                super.sublayout(Display.getWidth(), 70);
                                setExtent(Display.getWidth(), 70);
                            }
                        };
                        del_mgr3.setBackground(BackgroundFactory.createSolidBackground(Color.RED));
                        LabelField lbl3=new LabelField("VerticalFieldManager3");
                        del_mgr3.add(lbl3);
                        vert3.add(del_mgr3);
                    }
                }else if(field==btn4){
                    if(flag4==true){
                        flag4=false;
                        vert4.deleteAll();
    
                    }else{
                        flag4=true;
                        VerticalFieldManager del_mgr4=new VerticalFieldManager(){
                            protected void sublayout(int maxWidth, int maxHeight) {
                                super.sublayout(Display.getWidth(), 70);
                                setExtent(Display.getWidth(), 70);
                            }
                        };
                        del_mgr4.setBackground(BackgroundFactory.createSolidBackground(Color.CHOCOLATE));
                        LabelField lbl4=new LabelField("VerticalFieldManager4");
                        del_mgr4.add(lbl4);
                        vert4.add(del_mgr4);
                    }
                }
            }
    
    
        }
    }
    

    //这是 customButton 字段,这是从这个链接复制的 [自定义按钮1

    package com.hb.screens;
    
    import net.rim.device.api.ui.container.MainScreen;
    import net.rim.device.api.ui.Color;
    import net.rim.device.api.ui.Field;
    import net.rim.device.api.ui.Font;
    import net.rim.device.api.ui.Graphics;
    
    public class CustomButtonField extends Field
    {
    
        private int backgroundColour = Color.GRAY;
        private int highlightColour;
        private int fieldWidth;
        private int fieldHeight;
        private String text;
        private int padding = 8;
    
        public CustomButtonField(String text, int highlightColour)
        {
            super(Field.FOCUSABLE);
            this.text = text;
            this.highlightColour = highlightColour;
            Font defaultFont = Font.getDefault();
            fieldHeight = defaultFont.getHeight() + padding;
            fieldWidth = defaultFont.getAdvance(text) + (padding * 2);
            this.setPadding(2, 2, 2, 2);
        }
    
        protected boolean navigationClick(int status, int time)
        {
            fieldChangeNotify(1);
            return true;
        }
    
        protected void onFocus(int direction)
        {
            backgroundColour = highlightColour;
            invalidate();
        }
    
        protected void onUnfocus()
        {
            backgroundColour = Color.GRAY;
            invalidate();
        }
    
        public int getPreferredWidth()
        {
            return fieldWidth;
        }
    
        public int getPreferredHeight()
        {
            return fieldHeight;
        }
    
        protected void layout(int arg0, int arg1)
        {
            setExtent(getPreferredWidth(), getPreferredHeight());
        }
    
        protected void drawFocus(Graphics graphics, boolean on)
        {
    
        }
    
        protected void fieldChangeNotify(int context)
        {
            try
            {
                this.getChangeListener().fieldChanged(this, context);
            }
            catch (Exception e)
            {}
        }
    
        protected void paint(Graphics graphics)
        {
            graphics.setColor(backgroundColour);
            graphics.fillRoundRect(0, 0, fieldWidth, fieldHeight, 8, 8);
            graphics.setColor(Color.GRAY);
            graphics.drawRoundRect(0, 0, fieldWidth, fieldHeight, 8, 8);
            graphics.setColor(Color.WHITE);
            graphics.drawText(text, padding - 1, padding / 2 + 1);
        }
    }
    

    在点击 Button1 之前]

    点击Button1后]

    【讨论】:

      【解决方案3】:

      使用 delete() 方法。

      private VerticalFieldManager manager = new VerticalFieldManager();
      private BasicEditField bef = new BasicEditField();
      manager.add(bef);
      add(manager);
      manager.delete(bef);
      

      【讨论】:

        猜你喜欢
        • 2011-08-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-06-19
        • 2011-01-30
        相关资源
        最近更新 更多