Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

update ui in thread

Tags:

android

I create a class and extend it from view. also implemented the Runnable interface. In the onTouchEvent i call: new Thread(this).start().
This is my class:

public class test extend View interface Runnable{

    ----some code------

    public void onTouchEvent(MotionEvent event){
        ----somecode------
        new thread(this).start();
        ----somecode------
    }

    public void run(){
        -----somecode-------
        invalidate();
        -----somecode-------
    }
}

but i receive this error:

only the original thread that created a view hierarchy can touch its views

How can i fix this?

like image 727
Rasoul Taheri Avatar asked Jan 22 '26 11:01

Rasoul Taheri


1 Answers

Try to use

postInvalidate()

instead of

invalidate()

like image 132
ibit Avatar answered Jan 24 '26 02:01

ibit