PROBLEM
I have nearly 20 TextView
and I need to have do something to make their background color change dynamically.
For example: all TextView
have same default background color then after 5 sec first one's will turn red where others still same then after 5 more sec passed first TextView
's background color will turn to default and second TextView
's background color will be turn to red and it will go on like this.
I tried to put them in for loop in thread and handler but they changed all together. What should I do ?
I have tried this code
Thread color=new Thread() {
public void run() {
for(int i=2131230724;i<=2131230742;i++){
TextView currentText = (TextView) findViewById(i);
currentText.setBackgroundColor(Color.RED);
try {
sleep(2000);
currentText.setBackgroundColor(Color.TRANSPARENT);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
};
then I used
mHandler.post(color);
SOLUTION
I found a solution for my problem and sharing if someone else needed too.
Runnable myhandler=new Runnable() {
int id=2131230724;//First textView id
@Override
public void run() {
// TODO Auto-generated method stub
if(id==2131230724){
TextView currentText=(TextView)findViewById(R.id.egzersiz01_kelime1);
currentText.setBackgroundColor(Color.RED);
id++;
}
else if(id==2131230725){
TextView currentText=(TextView)findViewById(R.id.egzersiz01_kelime2);
currentText.setBackgroundColor(Color.RED);
TextView PreText=(TextView)findViewById(R.id.egzersiz01_kelime1);
PreText.setBackgroundColor(Color.TRANSPARENT);
id++;
}//And all other id's to else if as same as mine.
mHandler.postDelayed(myhandler, delay);
and in onCreate()
myhandler.run();
I have tried to use for loop to make it easy but it crashed and I had to write them all. Thanks for helping...