Setting and removing bitmap for button onfocus and onUnfocus
How to place bitmapFields in Manager while some buttons on it get focus.I tried following code but it is not working.`
when "button" get focus I need to add "field1" beside the button in Vfm.
button = new ImgButtonField("res/images/trans.png", Field.FOCUSABLE){
protected void onFocus(int direction) {
Vfm.insert(field1, button.getIndex()) ;
super.onFocus(direction);
invalidate();
开发者_JS百科 }
protected void onUnfocus() {
Vfm.delete(field1);
super.onUnfocus();
invalidate();
}
};
Try using add rather than insert ,sample code i tried
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);
}
Regards Rakesh Shankar.P
Try placing a NullField in the manager as a placeholder. The NullField
will not be visible. On focus, you can replace that NullField with field1.
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.
精彩评论