我想从另一个类访问videoview。如果我这样做了异常
Only the original thread that created a view hierarchy can touch its views.
android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:4607)
at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:835)
at android.view.View.requestLayout(View.java:15129)
at android.view.View.requestLayout(View.java:15129)
at android.view.View.requestLayout(View.java:15129)
at android.view.View.requestLayout(View.java:15129)
at android.view.View.requestLayout(View.java:15129)
at android.widget.VideoView.setVideoURI(VideoView.java:198)
at android.widget.VideoView.setVideoURI(VideoView.java:187)
at com.network.video.player.MainVideoActivity.PlayNext_Video(MainVideoActivity.java:452)
at com.network.video.player.ConnectToServer$HandleClientThread.Delete_file(ConnectToServer.java:116)
at com.network.video.player.ConnectToServer$HandleClientThread.run(ConnectToServer.java:244)
at java.lang.Thread.run(Thread.java:856)
有人可以告诉我如何从另一个类访问视图吗?
答案 0 :(得分:0)
您可以使用以下方法访问视图。
runOnUiThread(Runnable ac)
为此,将视图所在的活动传递给班级。
例如:
activity.runOnUiThread(new Runnable() {
public void run() {
//access here
}
});