如何将bitmapFields放在Manager中,同时它上面的某些按钮得到了重点。我尝试了下面的代码,但它没有工作。
当“按钮”获得焦点时,我需要在Vfm中的按钮旁添加“field1”。
button = new ImgButtonField("res/images/trans.png", Field.FOCUSABLE){
protected void onFocus(int direction) {
Vfm.insert(field1, button.getIndex()) ;
super.onFocus(direction);
invalidate();
}
protected void onUnfocus() {
Vfm.delete(field1);
super.onUnfocus();
invalidate();
}
};
答案 0 :(得分:0)
尝试使用add而不是insert,我试过的示例代码
ButtonField button,button1;
LabelField field1;
VerticalFieldManager vfm;
public MyScreen()
{
// Set the displayed title of the screen
setTitle("MyTitle");
vfm=new VerticalFieldManager();
field1=new LabelField("Sample");
button=new ButtonField("Sample"){
protected void onFocus(int direction) {
vfm.add(field1);
super.onFocus(direction);
invalidate();
}
protected void onUnfocus() {
vfm.delete(field1);
super.onUnfocus();
invalidate();
}
};
button1=new ButtonField("Sampl1");
this.add(button1);
this.add(button);
this.add(vfm);
}
此致 Rakesh Shankar.P
答案 1 :(得分:0)
尝试将NullField作为占位符放在管理器中。 NullField
将不可见。在焦点上,您可以用field1替换NullField。
NullField myNullField = new NullField();
button = new ImgButtonField("res/images/trans.png", Field.FOCUSABLE){
protected void onFocus(int direction) {
Vfm.replace(myNullField, field1) ;
super.onFocus(direction);
invalidate();
}
protected void onUnfocus() {
Vfm.replace(field1, myNullField);
super.onUnfocus();
invalidate();
}
};
//add fields to Vfm, including the myNullField placeholder.