blackberry buttonfield navigate on 2 second hold

152 views Asked by At

I am developing a blackberry app. I want to open an screen from the home screen when user will press one button and hold it for 2 seconds.

Any way?

Thanks.

2

There are 2 answers

0
V.J. On

Try this this will run successfully. Just change the Screen in PushScreen.

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();
0
sid_sket On

Here is the code for your question. I have make use of this BlackBerry LongClickListener implementation link which contains good explanation too.

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

}
}