Android "Shanxi illegal query Implementation 2" (parse the Web source and then the ListView display)---the client to obtain HTML source code

Source: Internet
Author: User

Don't say much nonsense, directly on the source

the last webpage source code in the result. 
 Public voidbtn (view view) {NewMyworker (). Execute ("Here's the URL"); }
An asynchronous operation that prevents the UI thread from blocking.
Private classMyworkerextendsAsynctask<string,void,string>
{ protectedString Doinbackground (string...urls) {StringBuilder builder=NewStringBuilder (100000); for(String url:urls) {
Defaulthttpclient Client
=Newdefaulthttpclient ();
HttpGet HttpGet
=Newhttpget (URL); Try{HttpResponse Execute=Client.execute (HttpGet);
InputStream content
=execute.getentity (). getcontent (); BufferedReader Buffer=NewBufferedReader (NewInputStreamReader (content)); String s= ""; while((s = buffer.readline ())! =NULL) {builder.append (s); } } Catch(Exception e) {e.printstacktrace (); } } returnbuilder.tostring (); } protected voidOnPostExecute (String result) {
    
Source code displayed in TextView TextView TextView
=(TextView) Findviewbyid (R.ID.TV1); Textview.settext (result); Get Source}}

Get results

Android "Shanxi illegal query Implementation 2" (parse the Web source and then the ListView display)---the client to obtain HTML source code

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.