Android Picasso get remote pictures and show

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.