有问题的按钮

时间:2011-06-13 11:33:16

标签: button user-interface blackberry

我制作了一个弹出屏幕,其中有一个

  

EditField和两个ButtonField

现在我面临非常奇怪的问题,有两个按钮一个是Cancel而另一个是Send button。现在,我添加的第一个按钮工作不正常,第二个按钮工作正常。为了简化此代码Cancel buttonSend button将起作用,而 ButtonField sendButton,cancelButton; PinPopup()//Constructor { super(new HorizontalFieldManager()); texts=new EditField("","",200,Field.EDITABLE); sendButton = new ButtonField(" Send "); sendButton.setChangeListener(this);
cancelButton = new ButtonField("Cancel"); cancelButton.setChangeListener(this); VerticalFieldManager _fieldManagerContext = new VerticalFieldManager(VerticalFieldManager.USE_ALL_WIDTH | VerticalFieldManager.USE_ALL_HEIGHT) {
public void sublayout(int width,int height) {
super.sublayout(width, height); int xpos = 10; int ypos = 40; Field field = getField(0); layoutChild(field, 280, 50); setPositionChild(field, xpos, ypos); Field field1 = getField(1); layoutChild(field1, 280, 50); setPositionChild(field1, xpos+10, ypos+80); Field field2 = getField(2); layoutChild(field2, 280, 50); setPositionChild(field2, xpos+145, ypos+80); setPosition(150, 220); setExtent(300, 220); } public void paint(){ Overrided } _fieldManagerContext.add(texts); _fieldManagerContext.add(sendButton); _fieldManagerContext.add(cancelButton); public void fieldChanged(Field field, int context) {

if(field==cancelButton) { Dialog.inform("Cancel");
}

if(field){ Dialog.inform("Send"); }
}

则不行。我在这里失踪的任何人都可以帮助我


if(field==sendButton){
Dialog.inform("Send");
}
更新

cancelButton = new ButtonField("Cancel") {
protected boolean navigationClick(int status, int time) {
return true;
    }
};
更新 我也尝试了这个,但是同样的问题现在让我们该怎么做
{{1}}

2 个答案:

答案 0 :(得分:0)

在您的FieldChangeListener中,对于发送,您正在检查if(field)而不是if(field == sendButton)

答案 1 :(得分:0)

我得到的问题因为我连续添加两个按钮,我使用了VerticalFieldManager来添加按钮,这就是我遇到问题的原因。为了解决方案,我在Horizo​​ntalFeildManager中添加了按钮,现在它正常工作

VerticalFieldManager _fieldManagerContext = new VerticalFieldManager(VerticalFieldManager.USE_ALL_WIDTH | VerticalFieldManager.USE_ALL_HEIGHT)

到这个

HorizontalFieldManager _fieldManagerContext = new HorizontalFieldManager(USE_ALL_WIDTH)