2012-03-27 34 views
0

我在屏幕的底部欄中放置了一個按鈕。底欄基本上是一個帶有背景圖像的水平欄目管理員。此按鈕(基本上是繼續按鈕)用於移動到下一個屏幕。但是如果我點擊管理器和按鈕外部,它將進入下一個屏幕。因此,單擊事件正在總經理上,下面是代碼:點擊事件在按鈕外部工作

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); 

這裏是click事件:

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

請幫我..我在BB大膽測試9790

+1

沒有其他重點領域。所以默認焦點將在按鈕中。 – Signare 2012-03-27 05:39:27

+2

一旦你點擊其他區域,你將獲得按鈕點擊事件。但是當你專注於其他領域時,你不會得到這個問題。所以添加一個Focusable字段進行測試比嘗試單擊按鈕.. – Hitarth 2012-03-27 06:26:12

回答

7

只需在添加按鈕之前添加一個nullfield即可。並使其可以專注。那可行。

像這樣加入nullField然後加button

hfmBtn.add(new nullField(Field.FOCUSABLE)); 
hfmBtn.add(btnContinue); 
add(hfmBtn); 
0

嘗試添加自定義按鈕,如下:

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; 
    } 
}); 
+0

我必須使用custome按鈕 – 2012-03-27 10:35:54

+0

我編輯了答案。現在可能對你更有用。 – rosco 2012-03-27 12:28:55

+0

你是什麼意思的調用代碼? – 2012-03-27 12:47:34

0

從這個就拿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

我也在同樣的方式哥們.. – 2012-03-27 12:26:38