Skip to content Skip to sidebar Skip to footer

Android Simple Textview Text Change With Timer

I am new to android and just starting through some tutorial videos. My requirement is initially i need to show the textview text to 'red' and after 5-10 sec, need to change it to '

Solution 1:

Try to Use Handler,

Handler h=new Handler();
h.postDelayed(new Runnable(){
public void run(){
//change your text here
}
}, time_delay);

Solution 2:

    _tv = (TextView) findViewById( R.id.textView1 );
     tv2 = (TextView) findViewById( R.id.textView2 );
    _tv.setText( "red" );
    _t = new Timer();

    _t.scheduleAtFixedRate( new TimerTask() {
            @Override
            public void run() {
                _count++;

                runOnUiThread(new Runnable() //run on ui thread
                 {
                  public void run() 
                  { 
                     tv2.setText(""+_count);
                     if(_count==5)
                     {
                    _tv.setText("hello red" );
                    _tv.setTextColor(Color.RED);
                     }
                 }
                 });
            }
        }, 1000, 1000 ); 

Post a Comment for "Android Simple Textview Text Change With Timer"