GithubHelp home page GithubHelp logo

ImageLoader with fragments about lazylist HOT 14 CLOSED

thest1 avatar thest1 commented on August 29, 2024
ImageLoader with fragments

from lazylist.

Comments (14)

 avatar commented on August 29, 2024

Hi Fedor, I used your lib in my project inside the fragment with a gridview. And it works just perfect.

Best regards, Nikolay

from lazylist.

dm77 avatar dm77 commented on August 29, 2024

Hi Fedor,

Like I promised, here is a demo app: https://github.com/DushyanthMaguluru/LazyListFragment that fails to set images correctly. I used a Cursor adapter in combination with a ContentProvider. You should notice that once you click on "Launch UserList" button on the main view, all the images are set to the default image. Only if you scroll down to the bottom and scroll back up, you will see the images being refreshed. And if you look at the logcat you will notice that you will only see these lines:

[ VERBOSE ] => ImageLoader: BitmapDisplayer Initialized
[ VERBOSE ] => ImageLoader: BitmapDisplayer Initialized
[ VERBOSE ] => ImageLoader: BitmapDisplayer Initialized
[ VERBOSE ] => ImageLoader: BitmapDisplayer Initialized
[ VERBOSE ] => ImageLoader: BitmapDisplayer Initialized

Note: I also tried setting the tag like you recommended on a different ticket, image.setTag(url). The results didn't change though.

Finally, I am sorry if there is actually a mistake in my implementation.

Thanks,
Dushyanth

from lazylist.

thest1 avatar thest1 commented on August 29, 2024

Dushyanth, thank you very much for the code.
I can see what's wrong with it. You pass application context to the adapter. That's why list items are inflated in application context and their getContext() is application not activity. Here's a fix https://github.com/thest1/LazyListFragment/commit/b15c2f635f90ed1b7c9eacd7357d2a077c4847c7.

Now the question is should I make a fix to allow ImageLoader work even under application context not just activity context. I'll have to create additional handlers for that as proposed by Vladislav gingo@e9e2c83. I'm not sure about that yet. Actually if you use ImageLoader you always have Activity and you can pass it not an application.

from lazylist.

dm77 avatar dm77 commented on August 29, 2024

Fedor, Thanks so much for correcting my mistake and proving that I am stupid :D. I am sorry to have wasted your time.

from lazylist.

thest1 avatar thest1 commented on August 29, 2024

Don't worry, you just helped me to figure out a weak place that can cause problems for many other people. So you contribution is highly appreciated.

from lazylist.

dm77 avatar dm77 commented on August 29, 2024

Thank you. As for changing the ImageLoader to use Handlers, I agree with your point that ImageLoader always has an activity. So not sure if its worth implementing the Handler architecture.

from lazylist.

johnnycube avatar johnnycube commented on August 29, 2024

Hi Fedor

I just recently ran into your mail regarding this issue and just became curious about testing in which situations Lazylist works with Fragments. I then saw, that this was covered here already ;)

But I tested your idea intensivly about using ImageView.post(Runnable r) and it works like a charm.

  photoToLoad.imageView.post(bd);

instead of

  Activity a=(Activity)photoToLoad.imageView.getContext();
        a.runOnUiThread(bd);

Works like a charm in every situation i encountered.

I also implemented a animation for showing the images. If your interested let me know.

With best regards

from lazylist.

thest1 avatar thest1 commented on August 29, 2024

I don't use post() any more. Official documentation ways post() will not
work when view is not attached to window
http://developer.android.com/reference/android/view/View.html#post(java.lang.Runnable).
And I really faced this issue. When I just started the application several
first images are just not displayed. Post() is not reliable.

If you have a nice animations code you can form my project on github and
commit your modifications. This way me or anybody else will be able to
reuse your modifications. Works for you?

12 марта 2012 г. 2:20 пользователь johnnycube <
[email protected]

написал:

Hi Fedor

I just recently ran into your mail regarding this issue and just became
curious about testing in which situations Lazylist works with Fragments. I
then saw, that this was covered here already ;)

But I tested your idea intensivly about using ImageView.post(Runnable r)
and it works like a charm.

 photoToLoad.imageView.post(bd);

instead of

 Activity a=(Activity)photoToLoad.imageView.getContext();
       a.runOnUiThread(bd);

Works like a charm in every situation i encountered.

I also implemented a animation for showing the images. If your interested
let me know.

With best regards


Reply to this email directly or view it on GitHub:
#7 (comment)

from lazylist.

segundoacosta avatar segundoacosta commented on August 29, 2024

Hi Fedor

public class MyFragment extends Fragment{

ImageLoader imgtmp;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState); 

    imgtmp= new ImageLoader ( getActivity().getApplicationContext() );

}

}

I'm doing everything from a fragment and I boot ERROR on line:

Activity a=(Activity)photoToLoad.imageView.getContext();

any solution to this?

from lazylist.

thest1 avatar thest1 commented on August 29, 2024

I happens because getContext() returns Application context not Activity context. I have just commited a fix, please try it 232d7f6. It uses hander to run the UI job so it doesn't depend on Activity. Should work fine for you now.

from lazylist.

segundoacosta avatar segundoacosta commented on August 29, 2024

Thank you!

works well, the only thing is that the images are too small, see if there's something wrong with my code, thanks for the support

from lazylist.

demo-Ashif avatar demo-Ashif commented on August 29, 2024

I'm getting error "Can't create handler inside thread that has not called looper.prepare() "
Please someone suggest.

from lazylist.

thest1 avatar thest1 commented on August 29, 2024

Probably because you create ImageLoader in some thread that is not UI thread.

from lazylist.

demo-Ashif avatar demo-Ashif commented on August 29, 2024

thanks , my problem is solved. I have one more issue. I want to resize my downloaded bitmap image . Alrdy seen this issue #19 and you suggested to disable it if dont need it. I just want to show image as 64 X 64 , so wht should i do ?

from lazylist.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.