Setting text of TextView in android in a loop

771 views Asked by At

i'm trying to set text of text view in a while loop as

 t = (TextView)findViewById(R.id.textView1);  
    while(true)  
    {  
     t.setText(hr+":"+":"min+":"+sec);  
      try{  
          Thread.sleep(1000);  
         }  
      catch(Exception e){}  
    }  

But while running the app text is not changing. when i removed the while loop then it was setting
text correctly.
why was so? Plz Help!!!!!!!!!strong text

1

There are 1 answers

1
Blackbelt On BEST ANSWER

you never change the values of hr, min and sec. Also you are calling Thread.sleep(1000); on the UI Thread, which is responsable to draw the text in your text view. Of course, it will be unable to do that while it is sleeping.