2011-05-10 107 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