Событие клика работает вне кнопки - PullRequest
0 голосов
/ 27 марта 2012

Я помещаю кнопку в нижнюю панель экрана.Нижняя панель - это горизонтальный менеджер полей с фоновым изображением.Теперь эта кнопка (в основном кнопка «Продолжить») используется для перехода к следующему экрану.но если я нажму в диспетчере и за пределами кнопки, он перейдет к следующему экрану.Итак, событие клика работает на общем менеджере, ниже код:

HorizontalFieldManager hfmBtn = new HorizontalFieldManager(Field.FIELD_BOTTOM)
    {
        protected void sublayout(int nMaxWidth, int nMaxHeight) 
        {
            height = Bitmap.getBitmapResource("buttom_bar.png").getHeight();
            super.sublayout(nMaxWidth, nMaxHeight);
            setExtent(getPreferredWidth(), getPreferredHeight());
        }

        public int getPreferredHeight() 
        {
            return height;
        }

        public int getPreferredWidth() 
        {
            return screenWidth;
        }
    };
    hfmBtn.setBackground(BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("buttom_bar.png")));
    btnContinue = new CustomButtonImageField("Continue", Bitmap.getBitmapResource("button_normal.png"), Bitmap.getBitmapResource("button_hover.png"),Field.FIELD_VCENTER);
    btnContinue.setChangeListener(this);
    btnContinue.setMargin(10, 0, 0, screenWidth/3);
    hfmBtn.add(btnContinue);
    add(hfmBtn);

А вот событие клика:

    public void fieldChanged(Field field, int context) 
{
    if(field == btnContinue)
    {
        UiApplication.getUiApplication().pushScreen(new SendListScreen(platformContext,strItemList));
    }
}

, пожалуйста, помогите мне .. Я тестирую в BB Bold 9790.

Ответы [ 3 ]

7 голосов
/ 27 марта 2012

Просто добавьте nullfield перед добавлением кнопки.И сделайте это фокусируемым.Это будет работать.

Как это добавить nullField затем Добавить button.

hfmBtn.add(new nullField(Field.FOCUSABLE)); 
hfmBtn.add(btnContinue);
add(hfmBtn);
0 голосов
/ 27 марта 2012

Возьмите PictureBackgroundButtonField.java по этой ссылке:

PictureBackgroundButtonField

, а затем попробуйте этот пример кода:

public class Abc extends MainScreen implements FieldChangeListener
{   
Bitmap bitmap=Bitmap.getBitmapResource("icon.png"),bitmapHover=Bitmap.getBitmapResource("iconHover.png");
PictureBackgroundButtonField continueBtn;
public Abc() 
{       
    createGUI();
}

private void createGUI() 
{   
    HorizontalFieldManager hr=new HorizontalFieldManager()
    {
        protected void sublayout(int maxWidth, int maxHeight) 
        {
            super.sublayout(Display.getWidth(),250);
            setExtent(Display.getWidth(),250);
        }
    };
    hr.add(new LabelField("Click The Below Button", Field.FOCUSABLE));
    continueBtn=new PictureBackgroundButtonField(bitmap.getWidth(), bitmap.getHeight(), Field.FIELD_HCENTER|Field.FOCUSABLE, bitmap, bitmapHover);
    continueBtn.setChangeListener(this);
    continueBtn.setMargin(50, 0, 0, 0);
    hr.add(continueBtn);
    hr.setBackground(BackgroundFactory.createSolidBackground(Color.GREEN));
    add(hr);
}

public void fieldChanged(Field field, int context)
{
    if(field==continueBtn)
    {
        Dialog.alert("Clicked");
    }
}           
}
0 голосов
/ 27 марта 2012

Попробуйте добавить свою пользовательскую кнопку следующим образом:

hfmBtn.add(new PictureBackgroundButtonField(bitmap.getWidth(), bitmap.getHeight(), Field.FIELD_HCENTER|Field.FOCUSABLE, bitmap, bitmapHover) {
    protected boolean invokeAction(int action) {
        // code to be executed when button is pressed
        return true;
    }
});
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...