I have another problem i can't solve by myselve.
My situation: I have four FrameLayouts in LinearLayouts.
I color them, set Layout hight and width at wrap content and just change the minwidth to use them as a status or progress bar.
To adjust the bars i have a method:
public void update_bars(){
FrameLayout bar_eat = (FrameLayout)findViewById(R.id.bar_eat);
FrameLayout bar_drink = (FrameLayout)findViewById(R.id.bar_drink);
FrameLayout bar_wash = (FrameLayout)findViewById(R.id.bar_wash);
FrameLayout bar_care = (FrameLayout)findViewById(R.id.bar_care);
bar_eat.setMinimumWidth((int)(((float)screen_part/1000)*eat));
bar_drink.setMinimumWidth((int)(((float)screen_part/1000)*drink));
bar_wash.setMinimumWidth((int)(((float)screen_part/1000)*wash));
bar_care.setMinimumWidth((int)(((float)screen_part/1000)*care));
}
This method works fine from everywhere in my activity. But i also want to call this update_bars() method every second so i made a timer for it.
private void update(){
Timer timer = new Timer();
timer.schedule(new TimerTask(){
@Override
public void run() {
update_bars()
}
},0,(1000* getResources().getInteger(R.integer.remove_speed_inSecond)));
But at this point it crashes....
The debugger says this:
Thread [<12> Timer-0] (ViewRootImpl$CalledFromWrongThreadException)
Timer$TimerImpl.run() Zeile: 290
So where it the problem? And what can i do? I woud be very happy if someone have an idear because i'm going crazy^^