【问题标题】:blackberry buttonfield navigate on 2 second hold黑莓按钮域导航 2 秒保持
【发布时间】:2011-10-24 18:26:08
【问题描述】:

我正在开发一个黑莓应用程序。当用户按下一个按钮并按住它 2 秒钟时,我想从主屏幕打开一个屏幕。

有办法吗?

谢谢。

【问题讨论】:

    标签: blackberry buttonfield


    【解决方案1】:

    这是您问题的代码。我已经使用了这个BlackBerry LongClickListener implementation 链接,其中也包含了很好的解释。

    public class HoldButtonScreen extends MainScreen implements FieldChangeListener {
    ButtonField _btnHold;
    Timer _timer;
    public HoldButtonScreen() {
    
        _btnHold = new ButtonField("Hold 2 sec to get popup")
                    {
                            protected boolean navigationClick(int status, int time) {
                                final Field _btnHold= this;
                                _timer = new Timer();
                                System.out.println("hi there");
                                UiApplication.getUiApplication().invokeLater(new Runnable() {
                                    public void run() {
                                        try{
                                            _timer.schedule(new TimerTask() {
                                                public void run() {
                                                    fieldChanged(_btnHold, 0);
                                                }}, 2000);
                                            }catch(Exception e){
                                                e.printStackTrace();
                                            }
                                        }
                                });
    
                                return true;
                            }
    
                            protected boolean navigationUnclick(int status, int time) {
                                System.out.println("hi unclick");
                                add(new LabelField("You have't hold button for 2 second."));
                                _timer.cancel();
                                return true;
                            }
    
                    };
        _btnHold.setChangeListener(this);
        add(_btnHold);
    }
    public void fieldChanged(Field field, int context) {
        UiApplication.getUiApplication().invokeLater(new Runnable() {
            public void run() {
                PopupScreen _popUpScreen = new PopupScreen(new VerticalFieldManager()){
                    public boolean onClose() {
                        close();
                        return true;
                    }
                };
                _popUpScreen.add(new LabelField("Hello , i am pop up after 2 second."));
                UiApplication.getUiApplication().pushScreen(_popUpScreen);
            }
        });
    
    }
    }
    

    【讨论】:

      【解决方案2】:

      试试这个会成功运行的。 只需在 PushScreen 中更改 Screen。

      private Thread splashTread;
      protected int _splashTime = 200;
      boolean countinue = true;
      splashTread = new Thread() {
          public void run() {
              while (countinue == true) {
                  try {
                      synchronized (this) {
                          wait(_splashTime);
                          }
                      } catch (InterruptedException e) {
                      } finally {
                          synchronized (UiApplication.getUiApplication().getAppEventLock()) {
                              UiApplication.getUiApplication().pushScreen(new Login());
                              SplashScreen.this.close();                              
                          }
                      countinue = false;
                      }
                  }
              }
          };
          splashTread.start();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多