2012-01-09 43 views
0

大家好,我坚持一个问题。我在一个屏幕中实现了一个ListField。在屏幕上方,我使用了一个HorizontalFieldManager来保存TitleLabel and Two Butons。我已经在列表字段的所有行上推入了一些屏幕。我的问题是,letSuppose当我在第四行,我选择了我想要的然后当我点击按钮,然后按钮工作,但我已经在第四行实施的屏幕也出现如何避免它。我正在Storm 9550模拟器上测试它,并使用Blackberry eclipse plugin5.0。我没有想法,请帮助我。ListField和按钮焦点问题在同一屏幕

导航点击,就如同这

protected boolean navigationClick(int status, int time) { 

    selectListAndButton(); 
    return true; 

}  

//这里是selectListAndButton方法

private selectListAndButton(){ 
Field field = getFieldWithFocus().getLeafFieldWithFocus(); 
    if(field == backCustomButton){ 
     //Popped the active Screen 

    }else if(field == saveCustomButton){ 
     //Saving some Data to the Database And pushing another Screen here 
        // problem comes here if i am at 2nd row of the listfield and selects 
        something from there and clicked on the button the screen which was 

        implemented at 2nd row also appears 

    } 

    else if (_list.getSelectedIndex() == 0){  
     //Called a date picker 

    } 
      else if (_list.getSelectedIndex() == 1){  
     //Pushed some another screen 

    } 

      else if (_list.getSelectedIndex() ==){ 
     //Pushed some another screen 

    } 

回答

0

我已经解决了。但迟到发布答案。我只是放弃了使用ListField的想法,因为我没有太多的行添加。所以我刚刚使用的小动作,而不是使用ListField我已经使用HorizontalFieldManager,它看起来像一个List所以一切工作正常。

感谢欢呼:)

1

你需要重写onTouchScreen和调用特定的功能依赖于事件的坐标和Field界限:

protected boolean touchEvent(TouchEvent message) { 
    if (isTouchInside(message, saveCustomButton)) { 
     save(); 
    } else { 
     showNextScreen(); 
    } 
} 

private boolean isTouchInside(TouchEvent messages, Field field) { 
    int eventCode = message.getEvent();  
    int touchX = message.getX(1); 
    int touchY = message.getY(1); 

    XYRect rect = field.getContentRect(); 

    return rect.contains(touchX, touchY); 
} 
+0

什么是'isTouchInside()'方法你可以探索多一点,为什么它不工作'navigationclick' – BBdev 2012-01-09 08:23:37

+0

的TouchEvent方法将调用navigationClick默认。他们使它与旧代码兼容。这工作非常好,除非你在控件/屏幕上重写navigationClick方法。我没有调试你的代码,但看起来像触摸事件不会调用onFocus为您的按钮或它在UI线程队列和navigationClick聚焦获得它之前的进程。 – 2012-01-09 21:01:35

+0

好吧,只要它能为我工作,我会给你一个kudo和+1,试图解释我thanx ... – BBdev 2012-01-10 03:57:44