Android simple textview text change with timer

前端 未结 2 790
情深已故
情深已故 2021-01-15 21:09

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 chang

相关标签:
2条回答
  • 2021-01-15 21:45

    Try to Use Handler,

    Handler h=new Handler();
    h.postDelayed(new Runnable(){
    public void run(){
    //change your text here
    }
    }, time_delay);
    
    0 讨论(0)
  • 2021-01-15 21:57
        _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 ); 
    
    0 讨论(0)
提交回复
热议问题