Asynchttpclient Open source framework to download pictures and text, the difference between volley and glide open source frameworks.

Source: Internet
Author: User

Asynchttpclient is a popular Android asynchronous web loading library on GitHub with: Https://github.com/loopj/android-async-http
Unlike the asynchttpclient and the open source framework volley and glide, unlike volley and glide, the cache policy has been implemented, and asynchttpclient itself does not implement a caching strategy.

The code is as follows:

1  Packagecom.lixu.asynchttpclient;2 3 ImportOrg.apache.http.Header;4 Importcom.loopj.android.http.AsyncHttpClient;5 ImportCom.loopj.android.http.AsyncHttpResponseHandler;6 Importandroid.app.Activity;7 ImportAndroid.graphics.Bitmap;8 Importandroid.graphics.BitmapFactory;9 ImportAndroid.os.Bundle;Ten ImportAndroid.widget.ImageView; One ImportAndroid.widget.TextView; A ImportAndroid.widget.Toast; -  -  Public classMainactivityextendsActivity { the     PrivateTextView TV; -     PrivateImageView IV; -  - @Override +     protected voidonCreate (Bundle savedinstancestate) { -         Super. OnCreate (savedinstancestate); + Setcontentview (r.layout.activity_main); A  atTV =(TextView) Findviewbyid (r.id.tv); -  -IV =(ImageView) Findviewbyid (R.ID.IV); -         //Web address for text and pictures -String URL1 = "http://www.baidu.com"; -  inString url2 = "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1183223528,3058066243&fm=116&gp= 0.jpg "; -  to Loadtxt (URL1); +  - LoadImage (URL2); the  *     } $ Panax Notoginseng     Private voidloadtxt (String url1) { -         //Create a Asynchttpclient object theAsynchttpclient AHC =Newasynchttpclient (); +Ahc.get (URL1,NewAsynchttpresponsehandler () { A  the @Override +              Public voidOnFailure (intARG0, header[] arg1,byte[] arg2, Throwable arg3) { -Toast.maketext (Getapplicationcontext (), "Error!! ", 0). Show (); $             } $  - @Override -              Public voidOnsuccess (intARG0, header[] arg1,byte[] arg2) { the                 //converts the obtained byte[] array to a string string -Tv.settext (NewString (arg2));Wuyi             } the         }); -     } Wu  -     Private voidLoadImage (String url2) { About  $Asynchttpclient AHC =Newasynchttpclient (); -Ahc.get (URL2,NewAsynchttpresponsehandler () { -  - @Override A              Public voidOnFailure (intARG0, header[] arg1,byte[] arg2, Throwable arg3) { +  theToast.maketext (Getapplicationcontext (), "Error!! ", 0). Show (); -             } $  the @Override the              Public voidOnsuccess (intARG0, header[] arg1,byte[] arg2) { the                 //Create a bitmap picture factory theBitmapfactory BF =Newbitmapfactory (); -                 //convert a byte array into a bitmap image using a picture factory inBitmap Bitmap = Bf.decodebytearray (arg2, 0, arg2.length); the  the Iv.setimagebitmap (bitmap); About  the             } the  the         }); +  -     } the}

XML file:

1 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 Xmlns:tools= "Http://schemas.android.com/tools"3 Android:id= "@+id/linearlayout1"4 Android:layout_width= "Match_parent"5 Android:layout_height= "Match_parent"6 android:orientation= "vertical" >7 8     <ScrollView9         Android:layout_width= "Match_parent"Ten Android:layout_height= "Match_parent" One Android:layout_weight= "1" > A  -         <TextView -             Android:id= "@+id/tv" the Android:layout_width= "Match_parent" - Android:layout_height= "Match_parent" /> -     </ScrollView> -  +     <ImageView -         Android:id= "@+id/iv" + Android:layout_width= "Match_parent" A Android:layout_height= "Match_parent" at Android:layout_weight= "1" /> -  - </LinearLayout>

Operating effect:

Asynchttpclient Open source framework to download pictures and text, the difference between volley and glide open source frameworks.

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.