程序代码:
Runnable runnable = new Runnable() {
int iCount = 0;
@Override
public void run() {
showTextView.setText("run:" + Integer.toString(iCount));//报这行出错
iCount++;
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
};
出错信息:android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.int iCount = 0;
@Override
public void run() {
showTextView.setText("run:" + Integer.toString(iCount));//报这行出错
iCount++;
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
};
通过响应Button的OnClickListener事件,创建了一个线程Thread thread = new Thread(runnable);
应该如何解决?