Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redraw view with intervals from thread

I need animate menu in custom view. It must be redrawed with intervals some times(about 10), but it redraws after thread stopped.

public void menuShift() {
    Runnable runnable  = new Runnable() {
        public void run() {
            while (TablesActivity.this.view.menuShifting) {
                try {
                    Thread.sleep(100) ;
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                TablesActivity.this.view.timerRefresh() ;
                TablesActivity.this.view.postInvalidate() ;
            }
        }
    } ;
    this.menuShiftThread = new Thread(runnable) ;
    this.menuShiftThread.run() ;
}
like image 774
amak Avatar asked Aug 06 '26 14:08

amak


1 Answers

this.menuShiftThread.run(); is the problem, you need

this.menuShiftThread.start()

to actualy start a new thread.

like image 74
Tomas Vondracek Avatar answered Aug 08 '26 08:08

Tomas Vondracek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!