0

This is default look when i launch activity.

After i play around with the wheel track pad then become like this. The button image or whole button lost.

Here is my custom buttonfield which extends ButtonField.

public class Custom_ButtonField extends ButtonField {
Bitmap mNormal;
Bitmap mFocused;
Bitmap mActive;

int mWidth;
int mHeight;

public Custom_ButtonField(Bitmap normal, Bitmap focused, 
    Bitmap active) {
    super(CONSUME_CLICK);
    mNormal = normal;
    mFocused = focused;
    mActive = active;
    mWidth = mNormal.getWidth();
    mHeight = mNormal.getHeight();
    setMargin(0, 0, 0, 0);
    setPadding(0, 0, 0, 0);
    setBorder(BorderFactory
                    .createSimpleBorder(new XYEdges(0, 0, 0, 0)));
    setBorder(VISUAL_STATE_ACTIVE, BorderFactory
                    .createSimpleBorder(new XYEdges(0, 0, 0, 0)));
}

protected void paint(Graphics graphics) {
    Bitmap bitmap = null;
    switch (getVisualState()) {
    case VISUAL_STATE_NORMAL:
            bitmap = mNormal;
            break;
    case VISUAL_STATE_FOCUS:
            bitmap = mFocused;
            break;
    case VISUAL_STATE_ACTIVE:
            bitmap = mActive;
            break;
    default:
            bitmap = mNormal;
    }
    graphics.drawBitmap(0, 0, bitmap.getWidth(), bitmap.getHeight(),
                    bitmap, 0, 0);
}

public int getPreferredWidth() {
    return mWidth;
}

public int getPreferredHeight() {
    return mHeight;
}

protected void layout(int width, int height) {
    setExtent(mWidth, mHeight);
}
}
Alan Lai
  • 1,094
  • 7
  • 18
  • 41

2 Answers2

1

It looks like you're trying to create a button with an image so you might be better off using the Advanced UI Library published by RIM. Take a look at the BitmapButtonField class.

donturner
  • 17,867
  • 8
  • 59
  • 81
0

Set Focusable on constructor.

super(Field.FOCUSABLE);
Michael Donohue
  • 11,776
  • 5
  • 31
  • 44
Suresh Kerai
  • 891
  • 1
  • 6
  • 20