Hi, I am using libgdx for my dice game in which you have to insert a three digit number with numbers in the range of 0-6.
When I google on how to have the on screen keyboard show numbers when opened they tell you to set the keyboard type of a textfield on numbers. On the TextField class in multi os engine this would look like:
textfield.setKeyboardType(UIKeyboardType.NumberPad);
In my custom IOSInput fork class, I added the textField.setKeyboardType(UIKeyboardType.NumberPad);
@Override
public void getTextInput(TextInputListener listener, String title, String text, String hint) {
buildUIAlertView(listener, title, text, hint).show();
}
/** Builds an {@link UIAlertView} with an added {@link UITextField} for inputting text.
* @param listener Text input listener
* @param title Dialog title
* @param text Text for text field
* @return UiAlertView */
private UIAlertView buildUIAlertView (final TextInputListener listener, String title, String text, String placeholder) {
UIAlertViewDelegate delegate = new UIAlertViewDelegate() {
@Override
public void alertViewClickedButtonAtIndex (UIAlertView alertView, @NInt long buttonIndex) {
if (buttonIndex == 0) {
// user clicked "Cancel" button
listener.canceled();
} else if (buttonIndex == 1) {
// user clicked "Ok" button
UITextField textField = alertView.textFieldAtIndex(0);
listener.input(textField.text());
}
}
@Override
public void alertViewCancel (UIAlertView alertView) {
listener.canceled();
}
};
// build the view
final UIAlertView uiAlertView = UIAlertView.alloc().init();
uiAlertView.setTitle(title);
uiAlertView.addButtonWithTitle("Cancel");
uiAlertView.addButtonWithTitle("Ok");
uiAlertView.setAlertViewStyle(UIAlertViewStyle.PlainTextInput);
uiAlertView.setDelegate(delegate);
UITextField textField = uiAlertView.textFieldAtIndex(0);
textField.setPlaceholder(placeholder);
textField.setText(text);
if (title.equals(CallInputDialog.ENTER_YOUR_CALL)) {
textField.setKeyboardType(UIKeyboardType.NumberPad);
}
return uiAlertView;
}
The CallInputDialog.ENTER_YOUR_CALL class is my dialog class for number imput that brings up the keyboard. So I detect when that title is set to modify the keyboard type.