How can I get a dialogbox with a textfield input so that I could get the user to enter a PIN number?
Asked
Active
Viewed 780 times
3 Answers
0
You can make one Popup screen
to meet your requiremement. See the Document here . And for implementation see this question on stackOverFlow.
Here is the code you can change it for your require ment
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);
}
}
0
You can create a CustomDialog which extends Screen. This will also help you to fetch the pin value user enter in the textbox.
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
}
}
Try this Hope this will help you.
while calling this dialog please refer to the code below..
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
UiApplication.getUiApplication().pushModalScreen(new CustomDialog());
}
});

Swati
- 1,179
- 9
- 28
-
Hi thank you very much Swati!!! but it throws and illegal state exception. should i put this class as an inner class?? or?? – Roses Jan 23 '12 at 17:45