afinal file Upload, download, picture loading instance

Source: Internet
Author: User

//afinal Frame Explanation Public classAfinalactivityextendsfinalactivity {@ViewInject (id=r.id.bt_afinal_loadimage,click = "Bt_afinal_loadimage_click")    PrivateButton Bt_afinal_loadimage; @ViewInject (ID= R.id.bt_afinal_gettext, click = "Bt_afinal_gettext_click")    PrivateButton Bt_afinal_gettext; @ViewInject (ID= r.id.bt_afinal_loadfile, click = "Bt_afinal_loadfile_click")    PrivateButton Bt_afinal_loadfile; @ViewInject (ID= R.id.bt_afinal_updatetext, click = "Bt_afinal_updatetext_click")    PrivateButton Bt_afinal_updatetext; @ViewInject (ID=r.id.iv_afinal)PrivateImageView iv_afinal; @ViewInject (ID=R.id.tv_afinal_result)PrivateTextView Tv_afinal_result; @ViewInject (ID=r.id.tv_title)PrivateTextView Tv_title; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (r.layout.activity_afinal);    InitData (); }    Private voidInitData () {Tv_title.settext ("Afinal"); }    //Load Picture Click event Handling     Public voidBt_afinal_loadimage_click (view view) {Finalbitmap Finalbitmap= Finalbitmap.create ( This); //picture that is displayed by default when a picture is requested by the networkfinalbitmap.configloadingimage (R.drawable.atguigu_logo); //Start loading PicturesFinalbitmap.display (iv_afinal, "http://img5.mtime.cn/mg/2016/10/11/160347.30270341.jpg"); }    //Click event handling for request text     Public voidBt_afinal_gettext_click (view view) {Finalhttp finalhttp=Newfinalhttp (); String URL= "Http://api.m.mtime.cn/PageSubArea/TrailerList.api"; Finalhttp.get (URL,NewAjaxcallback<object>() {@Override Public voidOnStart () {Tv_afinal_result.settext ("Start Loading"); Super. OnStart (); } @Override Public voidonsuccess (Object o) {//Show results after a successful loadTv_afinal_result.settext (o.tostring ()); Super. onsuccess (o); } @Override Public voidOnFailure (Throwable t,intErrorno, String strMsg) {Tv_afinal_result.settext ("Load Failed"); Super. OnFailure (t, Errorno, STRMSG);    }        }); }    //Click event handling for loading files     Public voidBt_afinal_loadfile_click (view view) {Finalhttp finalhttp=Newfinalhttp (); //request the address of a network resourceString url = "Http://vfx.mtime.cn/Video/2016/10/11/mp4/161011092841270064_480.mp4"; //storing video files to a local locationString target = Getfilesdir () + "/afinalmusic.mp4"; Finalhttp.download (URL, target,NewAjaxcallback<file>() {@Override Public voidonsuccess (file file) {Tv_afinal_result.settext ("Download file succeeded"); Super. onsuccess (file); } @Override Public voidOnFailure (Throwable t,intErrorno, String strMsg) {Tv_afinal_result.settext ("Download file failed"); Super. OnFailure (t, Errorno, STRMSG); } @Override Public voidOnStart () {Tv_afinal_result.settext ("Start Download"); Super. OnStart ();    }        }); }    //Handling of upload text click events     Public voidBt_afinal_updatetext_click (view view) {Finalhttp finalhttp=Newfinalhttp (); //where the files are uploaded to the serverString url = "Http://192.168.0.103:8080/FileUpload/FileUploadServlet"; Ajaxparams params=NewAjaxparams (); //get local resources to upload        Try{params.put ("File",NewFile (Getfilesdir () + "/afinalmusic.mp4")); } Catch(FileNotFoundException e) {e.printstacktrace (); } finalhttp.post (URL, params,NewAjaxcallback<object>() {@Override Public voidOnStart () {Tv_afinal_result.settext ("Start uploading"); Super. OnStart (); } @Override Public voidonsuccess (Object o) {tv_afinal_result.settext ("Upload succeeded"); Super. onsuccess (o); } @Override Public voidOnFailure (Throwable t,intErrorno, String strMsg) {Tv_afinal_result.settext ("Upload Failed"); Super. OnFailure (t, Errorno, STRMSG);    }        }); }}

afinal file Upload, download, picture loading instance

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.