Picasso is an open source Android graphics cache Library at square, address http://square.github.io/picasso/, which allows for image download and caching capabilities.
It is simple to use and simply requires a single line of code to fully implement the asynchronous loading of the image:
Picasso.with (View.getcontext ()). Load (newsitems.get (position). Getthumb ()). into (Holder.ivheader); // Picasso loading a preview image asynchronously
Images can be loaded without any other action at all, with the ability to cache, optimize the reuse of images in Recyclerview, and use sophisticated image compression algorithms to reduce memory consumption and bring your own level two cache
The following are examples of bloggers writing in adapter:
1 PackageSocialnews.linccy.com.socialnews.adapter;2 3 ImportAndroid.support.v7.widget.RecyclerView;4 ImportAndroid.view.LayoutInflater;5 ImportAndroid.view.View;6 ImportAndroid.view.ViewGroup;7 ImportAndroid.widget.ImageView;8 ImportAndroid.widget.TextView;9 Ten ImportCom.squareup.picasso.Picasso; One A Importjava.util.List; - - ImportButterknife. BindView; the ImportButterknife. Butterknife; - ImportSocialnews.linccy.com.socialnews.utils.NewsItem; - ImportSOCIALNEWS.LINCCY.COM.SOCIALNEWS.R; - + /** - * Created by LCCs on 2016/7/9. + */ A at Public classNewsitemadapterextendsRecyclerview.adapter<newsitemadapter.viewholder> { - - Private StaticList<newsitem>Newsitems; - Privateview view; - - PublicNewsitemadapter (list<newsitem>Newsitems) { in This. Newsitems =Newsitems; - } to + @Override - PublicViewholder Oncreateviewholder (viewgroup parent,intViewType) { theView = Layoutinflater.from (Parent.getcontext ()). Inflate (R.layout.recyclerview_cardview_item, parent,false); *Viewholder holder =Newviewholder (view); $ returnHolder;Panax Notoginseng } - the @Override + Public voidOnbindviewholder (Viewholder holder,intposition) { A Holder.tvTitle.setText (newsitems.get (position). GetTitle ()); the Holder.tvDetail.setText (newsitems.get (position). GETDESCR ()); + Holder.tvTime.setText (newsitems.get (position). GetTime ()); -Picasso.with (View.getcontext ()). Load (newsitems.get (position). Getthumb ()). into (Holder.ivheader);//Picasso loading a preview image asynchronously $ } $ - @Override - Public intGetItemCount () { the returnnewsitems.size (); - }Wuyi the - Public classViewholderextendsRecyclerview.viewholder { Wu @BindView (R.id.iv_header) - ImageView Ivheader; About $ @BindView (r.id.tv_title) - TextView Tvtitle; - @BindView (R.id.tv_detail) - TextView Tvdetail; A @BindView (r.id.tv_time) + TextView tvtime; the - PublicViewholder (View itemview) { $ Super(Itemview); theButterknife.bind ( This, Itemview); the } the } the}
:
Android Picasso get remote pictures and show