gingo/LazyList — comment on commit e9e2c8310f49768d78aad21bb6a29b831d4ef2f4
File:  line 0
By thest1:

Great! Would you be able to send me a simple demo with the problem?

17 февраля 2012 г. 9:40 пользователь Dushyanth Maguluru <
reply@reply.github.com
> написал:

> I agree with Gingo. I am using the ImageLoader in a list fragment with a
> cursor adpater and found that the code below is not working:
>
> ```
> BitmapDisplayer bd=new BitmapDisplayer(bmp, photoToLoad);
> Log.v(TAG, "Initialized bitmapdisplayer");
> Activity a=(Activity)photoToLoad.imageView.getContext();
> Log.v(TAG, "Activity initialized");
> Log.v(TAG, "Activity = " + a.getTitle());
> a.runOnUiThread(bd);
> ```
>
> In logcat, I only see one line:
>
> ```
> [ VERBOSE ] => ImageLoader: Initialized bitmapdisplayer
> ```
>
> I do not see the activity title displayed in the log. I ran the code
> through the debugger as well and the call to
> "(Activity)photoToLoad.imageView.getContext();" appears like it never
> completes
>
> As a work-around, I passed the current activity explicitly to the
> ImageLoader and everything works fine. So what I did:
>
> ```
> // Instance variable for activity
> private Activity mActivity;
>
> // Updated ImageLoader Constructor
> public ImageLoader(Activity activity) {
> fileCache=new FileCache(acivity.getApplicationContext());
> // Store the activity in an instance variable
> mActivity = activity;
> executorService=Executors.newFixedThreadPool(5);
> }
> ```
>
> And the updated code that calls the runOnUiThread:
>
> ```
> BitmapDisplayer bd=new BitmapDisplayer(bmp, photoToLoad);
> Log.v(TAG, "Initialized bitmapdisplayer");
> Log.v(TAG, "Activity = " + mActivity.getTitle());
> mActivity.runOnUiThread(bd);
> ```
>
> Now I see the title in my logcat output:
>
> ```
> [ VERBOSE ] => ImageLoader: Initialized bitmapdisplayer
> [ VERBOSE ] => ImageLoader: Activity = UserListActivity
> ```
>
> Also the images get refreshed correctly.
>
> Finally check Romain Guy's answer in
> http://stackoverflow.com/questions/3901590/get-activity-object-while-in-view-context.
> To quote him, "An Activity is a Context, but there is no guarantee that the
> Context used by a View is always an Activity." So I think what he says can
> be applied in this line:
>
> ```
> Activity a=(Activity)photoToLoad.imageView.getContext();
> ```
>
> I can recreate the problem on both the emulator and two android phones
> (original motorola droid running 2.2 and HTC Incredible 2.3)
>
> ---
> Reply to this email directly or view it on GitHub:
>
> https://github.com/gingo/LazyList/commit/e9e2c8310f49768d78aad21bb6a29b831d4ef2f4#commitcomment-976565
>