Android 使线程在多个ImageView中加载多个图像不起作用?

Android 使线程在多个ImageView中加载多个图像不起作用?,android,android-asynctask,imageview,Android,Android Asynctask,Imageview,我想在一个活动中用一个方法在五个ImageView中加载五个图像。这些图像是jpeg格式的,是短文件(最大500kb),因此我在Oncreate上尝试了这段代码: new Thread(new Runnable() { public void run(){ ins1 = (ImageView) findViewById(R.id.ins1); //and four more of this imagesviews ins5 = (ImageView) findViewB

我想在一个活动中用一个方法在五个ImageView中加载五个图像。这些图像是jpeg格式的,是短文件(最大500kb),因此我在
Oncreate
上尝试了这段代码:

new Thread(new Runnable() { 
            public void run(){
ins1 = (ImageView) findViewById(R.id.ins1);
//and four more of this imagesviews
ins5 = (ImageView) findViewById(R.id.ins5);

d1 = getResources().getDrawable(R.drawable.ins1);
//four more

ins1.setImageDrawable(d1);
// and four more

}
我得到了这个日志:

03-07 09:40:52.395: E/AndroidRuntime(3662): FATAL EXCEPTION: Thread-2727
03-07 09:40:52.395: E/AndroidRuntime(3662): Process: com.karlol.modernoapp, PID: 3662
03-07 09:40:52.395: E/AndroidRuntime(3662): android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.

我从未使用过AsyncTask,这可能是一个选项,请告诉我需要帮助

只有创建视图层次结构的原始线程才能接触其视图。

发生此错误的原因是您正在尝试在工作线程而不是UI线程中将drawable绑定到imageview

下面是asyntask的示例