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 "hello red".
I have tried two method alternatively. In first method its giving me exception while in second method its starting the application after given delay and directly show me the "hello red" text. I might be missing some basic concepts here. Could you pls help me ?
TextView myText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myText = (TextView)findViewById(R.id.displayTv);
// ------ first method start ---------
Thread timer = new Thread(){
public void run(){
try{
sleep(6000);
}catch(InterruptedException e){
e.printStackTrace();
}finally{
myText.setText("Hello red");
}
}
};
timer.start();
// ------ first method end ---------
// ------ second method start ---------
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
myText.setText("Hello red");
// ------ second method end ---------
}
}
Try to Use Handler,