我的ui 2按钮中有3个字段,一个在顶部,另一个在标签字段的按钮上...当标签字段获得焦点时,我希望按钮出现,我应该能够点击它们。 ..当标签字段失去焦点时,按钮应该消失。我可以这样做......
答案 0 :(得分:2)
将某个经理字段设置为按钮位置的占位符,然后在标签上添加FocusChangeListener,并使用add上的delete / focusChanged字段来显示/隐藏按钮。
<强>更新强>
由于字段中的每个焦点更改都可能会更改布局,因此最好将侦听器添加到添加到屏幕和占位符的每个字段中:
class Scr extends MainScreen {
HorizontalFieldManager placeholder = new HorizontalFieldManager() {
public void add(Field field) {
if (field.getFocusListener() != null)
field.setFocusListener(null);
field.setFocusListener(focusListener);
super.add(field);
}
};
ButtonField buttonField = new ButtonField("button",
ButtonField.CONSUME_CLICK);
LabelField labelField = new LabelField("label", FOCUSABLE);
public Scr() {
add(placeholder);
add(labelField);
add(new LabelField("label2", FOCUSABLE));
}
public void add(Field field) {
if (!(field instanceof Manager)) {
if (field.getFocusListener() != null)
field.setFocusListener(null);
field.setFocusListener(focusListener);
}
super.add(field);
}
FocusChangeListener focusListener = new FocusChangeListener() {
public void focusChanged(Field field, int eventType) {
if (eventType == FOCUS_GAINED) {
if (field == labelField) {
if (buttonField.getManager() == null)
placeholder.add(buttonField);
} else if (field != buttonField)
placeholder.delete(buttonField);
}
}
};
}