我有三个按钮在顶部,就像tab和三个垂直管理器,有定制设计。我想在我点击按钮时隐藏垂直场管理器(例如在android中有一个属性GONE和VISIBLE)你可以在我的屏幕上看到。任何身体都有我的问题的想法请发送。
答案 0 :(得分:3)
假设您创建vfm为
vfm=new VerticalFieldManager()
然后将其添加到屏幕上的另一位经理
hfm.add(vfm);
您可以通过执行
删除之前添加的垂直字段管理器hfm.delete(vfm);
您还可以通过调用
删除管理器中的所有字段hfm.deleteAll()
答案 1 :(得分:2)
这是总课程,当你第一次点击Button1时BLUE颜色会再次消失点击Button1 BLUE颜色将显示相同的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字段 [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后]
答案 2 :(得分:1)
使用delete()方法。
private VerticalFieldManager manager = new VerticalFieldManager();
private BasicEditField bef = new BasicEditField();
manager.add(bef);
add(manager);
manager.delete(bef);