2011-05-10 114 views
1

我正在實現自定義ImageButton觸控設備(9500,9550,9800,...) 我有問題,點擊(觸摸)外部字段生成事件在焦點領域。(當擴展FieldBitmapField黑莓點擊外部字段

我可以通過將焦點移到空場來解決它,但這不是很好。 奇怪的是,這種行爲是爲Field,BitmapField但不是ButtonField。 它真的好像是當ButtonField集中時,外部點擊不會生成按鈕事件。

我嘗試延長ButtonField,但我無法擺脫愚蠢的按鈕背景。

所以我的問題; FieldButtonField之間在Field之外導致產生事件的行爲有什麼不同?

我這是怎麼刪除按鈕背景:

// cahange button border 
    setBorder(BorderFactory 
      .createSimpleBorder(new XYEdges(0, 0, 0, 0))); 
    setBorder(VISUAL_STATE_ACTIVE, BorderFactory 
      .createSimpleBorder(new XYEdges(0, 0, 0, 0))); 

回答

0

你只需要在你的TouchEvent(增加檢查)的ImageButton的

protected boolean touchEvent(TouchEvent message) { 
    //make sure the touch is withing the bounds of our Field 
    if(message.getX(1) < 0 || message.getX(1) > getWidth() || message.getY(1) < 0 || message.getY(1) > getHeight()) { 
     return false; 
    } 

    //Do your work 
} 

觸摸事件被髮送到聚焦場即使它實際上並不在Field上,也必須返回false,以便包含的管理器知道將其發送到將接受它的下一個字段(觸摸所在的字段,或者如果它位於空白區域,則爲空) 。

編輯: 要刪除按鈕的背景下,覆蓋protected void applyTheme() {}

+0

是的,我知道這個檢查,但我的問題是有什麼區別,爲什麼ButtonField字段只接受內點擊?順便說一句。在此期間,我想出瞭如何擺脫按鈕背景,所以現在buttonfield完美地爲我工作 – Janci 2011-05-10 15:03:34

+0

@Janci你可以請分享你是如何獲得按鈕背景的? – 2011-06-09 12:38:34

+0

@TechnodHr我已更新我的答案,以顯示如何刪除按鈕裝飾 – jprofitt 2011-06-09 13:10:06