尝试通过ImageLoader类更新Appcompact Activity的UI(使用线程)

时间:2016-08-04 12:39:35

标签: android multithreading bitmap universal-image-loader

ImageLoader.Class

 {
   BitmapDisplayer bd=new BitmapDisplayer(bmp, photoToLoad);
   Activity a=(Activity)photoToLoad.imageView.getContext();
   a.runOnUiThread(bd);
 }
   class BitmapDisplayer implements Runnable
{
    Bitmap bitmap;
    PhotoToLoad photoToLoad;

    public BitmapDisplayer(Bitmap b, PhotoToLoad p){bitmap=b;photoToLoad=p;}

    public void run()
    {
        if(imageViewReused(photoToLoad)) {
            Log.d("A","Returning");
            return;
        }
            if(bitmap!=null) {
                Log.d("A","Setting Image");
                photoToLoad.imageView.setImageBitmap(bitmap);
            }
                else {
                Log.d("A","Setting ICON");
                photoToLoad.imageView.setImageResource(stub_id);
            }
                Log.d("A","we are in ui thread");
    }
}

MainActivity.class

   public class Main_Menu_Activity  extends AppCompatActivity
   implements NavigationView.OnNavigationItemSelectedListener{
    }

但是当我在MainActivity中通过“扩展活动”替换“扩展APPCOMPACTACTIVTY”时,THREAD - “BitmapDisplayer”执行得很精细。

0 个答案:

没有答案