Ventana emergente personalizada para funcionar como información sobre herramientas sin tiempo de espera
Frecuentes
Visto 424 veces
0
Necesito crear una ventana emergente personalizada para que funcione como una información sobre herramientas. ¿Cómo puedo lograrlo? He trabajado en un código, consulte y dígame dónde necesito mejorar.
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.PopupScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
public class ToolTip extends PopupScreen{
private static VerticalFieldManager vfm;
private LabelField lbl;
private int xPosition;
private int yPosition;
private String message;
public ToolTip(String message,int xPos,int yPos){
super(vfm);
this.xPosition=xPos;
this.yPosition=yPos;
this.message=message;
vfm=new VerticalFieldManager(){
protected void paint(Graphics graphics) {
graphics.setColor(0x00FFFFFF);
graphics.fillRect(0,0,getWidth(),getHeight());
graphics.setColor(0x00000000);
graphics.drawRect(0,0,getWidth(),getHeight());
super.paint(graphics);
}
};
lbl=new LabelField(message);
vfm.add(lbl);
}
protected void sublayout(int width, int height) {
super.sublayout(width, height);
setExtent(lbl.getPreferredWidth(), lbl.getPreferredHeight());
setPosition(xPosition, yPosition);
}
}
me sale un error de NullPointer Exception en super(vfm)
porque vfm es nulo cuando lo uso de la siguiente manera. ¿Cómo puedo optimizar mi código?
ButtonField bf1=new ButtonField("Login"){
protected boolean navigationClick(int status, int time) {
UiApplication.getUiApplication().pushScreen(new ToolTip("Hello ", 50, 50));
return super.navigationClick(status, time);
}
};
add(bf1);
1 Respuestas
1
Pasar una instancia inicializada de VerticalFieldManager
a super(..)
of PopupScreen
. Verifique el siguiente código.
class ToolTip extends PopupScreen {
private static VerticalFieldManager vfm = new VerticalFieldManager() {
protected void paint(Graphics graphics) {
graphics.setColor(0x00FFFFFF);
graphics.fillRect(0, 0, getWidth(), getHeight());
graphics.setColor(0x00000000);
graphics.drawRect(0, 0, getWidth(), getHeight());
super.paint(graphics);
}
};
// other codes
public ToolTip(String message, int xPos, int yPos) {
super(vfm);
// other codes
}
protected void sublayout(int width, int height) {
// other codes
}
}
Código actualizado para soporte de fondo personalizado
class ToolTip extends PopupScreen {
private int xPosition;
private int yPosition;
public ToolTip(String message, int xPos, int yPos) {
super(new VerticalFieldManager());
// Define and set background here
// Use - BackgroundFactory.createBitmapBackground(bitmap) for bitmap background
getDelegate().setBackground(BackgroundFactory.createSolidBackground(Color.RED));
// Add other UI Field here
this.xPosition=xPos;
this.yPosition=yPos;
add(new LabelField(message));
// other codes
}
// Empty implementation of this will disable default rounded border.
protected void applyTheme() {
}
protected void sublayout(int width, int height) {
super.sublayout(width, height);
setPosition(xPosition, yPosition);
}
}
Tienes que usar getDelegate().setBackground(..)
para establecer el fondo. revisa la clase BackgroundFactory
para crear un fondo personalizado.
Respondido el 12 de junio de 12 a las 13:06
¿Cómo es un fondo negro? ¿Cómo puedo eliminar que solo necesito el Rectángulo relleno o una imagen como fondo que se puede pasar como un parámetro a la clase? - - Yatin
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas blackberry popup tooltip customization or haz tu propia pregunta.
i get an error of Null Field Exception
- no existe tal Excepción en BlackBerry. Publique también el seguimiento de la pila y el mensaje de excepción. - RupakTambién necesito anular el método paint () de vfm - Yatin
@Rupak: ¿Cómo es un fondo negro? ¿Cómo puedo eliminar que solo necesito el Rectángulo relleno o una imagen como fondo que se puede pasar como parámetro a la clase? Yatin