Change the TextView color Continuosly using UIThread
Have a nice day. Now i write the code for changing the textview continuosly using UIThread.
Just try out.
handler = new Handler();
new Thread(new Runnable() {
@Override
public void run() {
final int totalCount=1000;
// TODO Auto-generated method stub
for(int i=0;i<totalCount;i++){
try {
runOnUiThread(new Runnable() {
public void run() {
Random r = new Random();
colorText.setTextColor(Color.rgb(r.nextInt(256),
r.nextInt(256), r.nextInt(256)));
}
});
Thread.sleep(totalCount);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}).start();
Textview is continuously changing the textcolor. I'm set the 1000 milliseconds (1 Second).
Just try out.
handler = new Handler();
new Thread(new Runnable() {
@Override
public void run() {
final int totalCount=1000;
// TODO Auto-generated method stub
for(int i=0;i<totalCount;i++){
try {
runOnUiThread(new Runnable() {
public void run() {
Random r = new Random();
colorText.setTextColor(Color.rgb(r.nextInt(256),
r.nextInt(256), r.nextInt(256)));
}
});
Thread.sleep(totalCount);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}).start();
Textview is continuously changing the textcolor. I'm set the 1000 milliseconds (1 Second).
Comments