android using ViewPager to show images -
i'd download bunch of images web , show them using custom pageradapter. can slide browse of these images.
i define activity named photoslideactivity
extends fragmentactivity
. in activity, have own pageradapter
. following code:
private class photoslidepageradapter extends fragmentstatepageradapter { private final int msize; public photoslidepageradapter(fragmentmanager fm, int size) { super(fm); msize = size; } @override public fragment getitem(int position) { photourl photourl = new photourl(position); return photoslidepagefragment.create(photourl.makephotourl()); } @override public int getcount() { return msize; } }
the following photoslidepagefragment
. mimagefetcher
class download images asynchronously.
public class photoslidepagefragment extends fragment { @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { final view v = inflater.inflate(r.layout.fragment_photo_slide_page, container, false); mimageview = (imageview) v.findviewbyid(r.id.imageview1); } @override public void onactivitycreated(bundle savedinstancestate) { super.onactivitycreated(savedinstancestate); // use parent activity load image asynchronously imageview if (photoslideactivity.class.isinstance(getactivity())) { mimagefetcher = ((photoslideactivity) getactivity()).getimagefetcher(); mimagefetcher.loadimage(mimageurl, mimageview); } }
(1) original idea put mimagefetcher.loadimage(mimageurl, mimageview);
in oncreateview
. there difference between putting in oncreateview
, in onactivitycreated
?
(2) if replace did in onactivitycreated
mimagefetcher = new imagefetcher(); mimagefetcher.loadimage(mimageurl, mimageview);
? doing means use fragment
load image asynchronously. there bad effects doing this?
use can use lazylist fetch data website(url). download following example github
https://github.com/thest1/lazylist
and adapter data use in swipe change image example
Comments
Post a Comment