Blackberry 黑莓中带有文本框的对话框
如何获得带有文本字段输入的对话框,以便让用户输入PIN码?您可以制作一个Blackberry 黑莓中带有文本框的对话框,blackberry,java-me,blackberry-jde,Blackberry,Java Me,Blackberry Jde,如何获得带有文本字段输入的对话框,以便让用户输入PIN码?您可以制作一个弹出屏幕来满足您的要求。看。以及实施 这是代码,您可以根据需要进行更改 public class PinPopup extends PopupScreen //implements FieldChangeListener { public static EditField texts; PinPopup() { super(new HorizontalFieldManager()); Font f = Font.get
弹出屏幕来满足您的要求。看。以及实施
这是代码,您可以根据需要进行更改
public class PinPopup extends PopupScreen //implements FieldChangeListener
{
public static EditField texts;
PinPopup()
{
super(new HorizontalFieldManager());
Font f = Font.getDefault().derive(Font.BOLD, 16);
setFont(f);
texts=new EditField("Pin: ","",15 , Field.EDITABLE);
ButtonField sendButton = new ButtonField(" Send "){
protected boolean navigationClick(int status, int time) {
//Do something with button
return true;
}
};
ButtonField cancelButton = new ButtonField("Cancel"){
protected boolean navigationClick(int status, int time) {
//Do something with button
return true;
}
};
Manager _fieldManagerContext = new Manager(USE_ALL_WIDTH)
{
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, ypos+40);
Field field2 = getField(2);
layoutChild(field2, 280, 50);
setPositionChild(field2, xpos+20, ypos+100);
setPosition(300, 300);
setExtent(300, 300);
}
public void paint(Graphics graphics)
{
//graphics.setColor(Color.WHITE);
Font f = Font.getDefault().derive(Font.BOLD, 16);
graphics.setFont(f);
graphics.drawText("SEND PIN",90, 20,0,200);
//graphics.drawText( _userName,110,40,0,200);
graphics.setColor(Color.WHITE);
super.paint(graphics);
}
};
_fieldManagerContext.add(texts);
_fieldManagerContext.add(sendButton);
_fieldManagerContext.add(cancelButton);
add(_fieldManagerContext);
}
}
您可以创建一个扩展屏幕的自定义对话框。这也将帮助您获取用户在文本框中输入的pin值
public class CustomDialog extends Screen
{
public CustomDialog()
{
super(new VerticalFieldManager(), Screen.DEFAULT_CLOSE);
//add the whole UI here
}
//control the height and width of the Dialog with the help of this function
protected void sublayout(int width, int height)
{
layoutDelegate(width - 80, height - 80);
setPositionDelegate(10, 10);
setExtent(width - 60, Math.min(height - 60, getDelegate().getHeight() + 20));
setPosition(30, (height - getHeight())/2); // sets the position on the screen
}
}
试试这个,希望对你有帮助
调用此对话框时,请参考下面的代码
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
UiApplication.getUiApplication().pushModalScreen(new CustomDialog());
}
});
或者,您也可以查看我的博客文章,了解如何从自定义对话框中获取输入。您好,非常感谢Swati!!!但它抛出了一个非法的状态异常。我应该把这个类作为一个内部类吗??或