Reputation: 3
So i have implemented a timer that calls a timertask extension called labelsTimer. The method should change the label of the text to that stipulated in the code but instead throws a error
android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
this is the code
public class labelsTimer extends TimerTask {
EditText label;
labelsTimer(EditText label)
{ super();
this.label = label;
}
@Override
public void run()
{
System.out.print("fsdfsd");
label.setText("hehehehe");
}
}
Upvotes: 0
Views: 50
Reputation: 4907
Use this
public void run(){
runOnUiThread(new Runnable() {
@Override
public void run() {
label.setText("hehehehe");
}
});
}
Upvotes: 1
Reputation: 916
change the label in this wrapper thread
try {
runOnUiThread(new Runnable() {
@Override
public void run() {
label.setText("hehehehe");
}
});
} catch (InterruptedException e) {
e.printStackTrace();
}
Upvotes: 0