AlfredoVR
AlfredoVR

Reputation: 4297

How to change a textview text with a delay without using threads in android?

I need to sequentially show a changing text with 1 second or half a second between changes. How can i achieve this without using threads in android?

Upvotes: 3

Views: 1523

Answers (3)

Idistic
Idistic

Reputation: 6311

I would just use a handler and a runnable in your activity, fairly simple

    Handler textNextHandler = new Handler(); 

    final Runnable textTimer = new Runnable() 
    {
        public void run() 
        {
           // ROTATE YOUR TEXT HERE THEN TELL IT HOW LONG TO DELAY UNTIL NEXT
           textNextHandler.postDelayed(this, 500);  
        }
    };

    @Override
    public void onResume() {
        super.onResume();
        textNextHandler.postDelayed(textTimer,500); 
    }       

    @Override
    public void onPause() {
        super.onPause();
        textNextHandler.removeCallbacks(textTimer);
    }

Upvotes: 3

Nicklas A.
Nicklas A.

Reputation: 7061

You could try Activity.runOnUiThread(Runnable)

Upvotes: 0

mibollma
mibollma

Reputation: 15108

Try using postDelayed()

Upvotes: 0

Related Questions