I know if I want to use a thread in UI group, must use a handler. because, android UI is single thread model. so, If another thread accesses the UI, occur
android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
so I use handler but same occur error message.
private static TextView sTextView; //global variable
public void showText(final TextView textView) {
sTextView = textView;
sTextView.findViewById(R.id.text);
Looper.prepare();
final Handler handler = new Handler();
new Thread(new Runnable() {
@Override
public void run() {
handler.post(new Runnable() {
@Override
public void run() {
sTextView.setText("123123123");
}
});
}
}).start();
Looper.loop();
}
and showText called
private VideoCapture videoCapture; //global variable
private TextView mText; //global variable
public void beginCapture() {
videoCapture.showText(mText);
}
and I build. but occur error.