Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Trusted Contributor
Posts: 141
Registered: ‎02-15-2012
My Device: 9800
My Carrier: Airtel

Edit FIeld - center and with numeric keypad

Hi,

 

      I want a text field, which is using for enter numbers. I want to make it center. And want to allow it with numeric keypad.

 

It was working fine with BB OS 5 and when using BB OS 6 / 7 / 7.1, I was unable to show numeric keypad.

 

Follwing is the code:

 

txtEventNumber = new RichTextField(RichTextField.TEXT_ALIGN_HCENTER) {
public void paint(Graphics graphics) {
super.paint(graphics);
int oldColor = Color.GRAY;

graphics.setBackgroundColor(Color.WHITE);
graphics.setColor(TEXT_COLOR);
Font font = this.getFont().derive(Font.EMBOSSED_EFFECT, 20);
this.setFont(font);

graphics.drawRoundRect(0, 0, getWidth(), getHeight(), 10, 10);
graphics.setColor(oldColor);

super.paint(graphics);
}

public int getPreferredHeight() {
return super.getPreferredHeight() + ADD_MARGIN;
}

protected void onFocus(int direction) {
if (Touchscreen.isSupported() && getScreen().getVirtualKeyboard() != null)
// Show keyboard
getScreen().getVirtualKeyboard().setVisibility(VirtualKeyboard.SHOW);
};

protected void onUnfocus() {
if (Touchscreen.isSupported() && getScreen().getVirtualKeyboard() != null)
// Hide keyboard
getScreen().getVirtualKeyboard().setVisibility(VirtualKeyboard.HIDE_FORCE);
};
};
txtEventNumber.setEditable(true);
// can enter only numeric digits
if (Touchscreen.isSupported())
// show numeric keypad
txtEventNumber.setFilter(TextFilter.get(TextFilter.DEFAULT_SMART_PHONE));
else
txtEventNumber.setFilter(TextFilter.get(TextFilter.REAL_NUMERIC));

txtEventNumber.setMargin(10, 10, 0, 10);

Contributor
Posts: 43
Registered: ‎11-30-2011
My Device: Dev Alpha, 8520
My Carrier: Vodafone

Re: Edit FIeld - center and with numeric keypad

why do all the effort to show and hide the keyboard? just use a NumericTextFilter according to your needs on the text field. The device will automatically handle what keyboard to show and what not to.



I've got 99 problems and eclipse is all of them


Twitter

Trusted Contributor
Posts: 141
Registered: ‎02-15-2012
My Device: 9800
My Carrier: Airtel

Re: Edit FIeld - center and with numeric keypad

Hi newton53,

                         NumericTextFilter is not useful to me.

 

I am using it in OS 6 and OS 7.1.

When I am using EditField, I was able to get numeric keypad(using TextFilter) but was unable to set the text in CENTER horizontally.

 

And When using RichTextField, I was able to set text in CENTER horizontally(using RichTextField.TEXT_ALIGN_HCENTER). But was unable to show numeric keypad.

 

Please provide me any code to use edit field, which can I set horizontally CENTER and can show Numeric keypad for OS 6(and later).

It is most needed.