The Android client that made the Web page (ii)

Source: Internet
Author: User

3. Display Content

Get the properties you need, and the next step is to show

Mainactivity using a ListView to display the contents of the Newslist collection

Newscontentactivity passes the link from mainactivity through intent, using a webview to show the details of the news.

Note that the WebView load URL uses the Loaddatawithbaseurl () method, and the first property is BaseURL, which is used to make the link property of the relative address into an absolute address.

This HTML file header

  String head= ";

Allows images and video players to fit the size of the phone

 Packagecom.saltwater.animenews;Importandroid.content.Intent;ImportAndroid.os.Bundle;ImportAndroid.os.Handler;ImportAndroid.os.Message;Importandroid.support.annotation.StringRes;ImportAndroid.support.design.widget.FloatingActionButton;ImportAndroid.support.design.widget.Snackbar;Importandroid.support.v7.app.AppCompatActivity;ImportAndroid.support.v7.widget.Toolbar;ImportAndroid.view.View;ImportAndroid.webkit.WebView;ImportOrg.jsoup.Jsoup;Importorg.jsoup.nodes.Document;Importorg.jsoup.nodes.Element;Importorg.jsoup.select.Elements;Importjava.io.IOException; Public classNewscontentactivityextendsappcompatactivity {String baseUrl= "http://www.animenewsnetwork.com/"; //String testurl= "news/2016-10-30/angel-beats-heaven-door-manga-ends-new-manga-of-true-arc-starts-in-2017/. 108274 ";@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (r.layout.activity_news_content); FinalHandler handler=NewHandler () {@Override Public voidhandlemessage (Message msg) {WebView wvcontent=(WebView) Findviewbyid (r.id.wvcontent); Wvcontent.getsettings (). setjavascriptenabled (true); Wvcontent.loaddatawithbaseurl (Baseurl,msg.obj.tostring (),"Text/html", "Utf-8",NULL);        }        }; /*Get news content*/        NewThread (NewRunnable () {@Override Public voidrun () {Try{Intent Intent=getintent (); String Link=intent.getstringextra ("link"); Document Doc= Jsoup.connect (baseurl+link). get (); String Head= "; String bodyhtml=doc.select ("div[class=meat]>*"). toString (); String HTML= "; Message Message=NewMessage (); Message.obj=HTML;                Handler.sendmessage (message); }                Catch(Exception e) {e.printstacktrace ();    }}). Start (); }}

The item layout of the ListView

News_list_item.xml

<?xml version= "1.0" encoding= "Utf-8"? ><relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content" > <TextView Android:id= "@+id/tvtitle"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:text= "title"android:textsize= "22DP"Android:textstyle= "Bold"Android:textcolor= "@color/colorprimarydark"Android:layout_alignparenttop= "true"Android:layout_alignparentleft= "true"Android:maxlines= "3"android:ellipsize= "End"/> <TextView Android:id= "@+id/tvpubdata"Android:layout_width= "Wrap_content"Android:layout_height= "22DP"Android:layout_below= "@id/tvtitle"Android:layout_alignparentleft= "true"Android:text= "Time"/> <TextView Android:id= "@+id/tvcategory"Android:layout_width= "Wrap_content"Android:layout_height= "22DP"Android:layout_below= "@id/tvtitle"Android:layout_alignparentright= "true"Android:text= "Category"/> <LinearLayout android:layout_width= "Match_parent"Android:layout_height= "120DP"Android:layout_below= "@id/tvpubdata"Android:weightsum= "1" > <TextView Android:id= "@+id/tvdescription"Android:layout_width= "0DP"Android:layout_height= "Wrap_content"Android:layout_weight= "0.5"android:textsize= "18DP"Android:textcolor= "@color/colorblack"Android:maxlines= "5"android:ellipsize= "End"Android:text= "Description"/> <ImageView Android:id= "@+id/imgviewcover"Android:layout_width= "0DP"Android:layout_height= "120DP"Android:layout_weight= "0.5"android:src= "@mipmap/ic_launcher"/> </LinearLayout></RelativeLayout>
5. Cover display (TODO)

The Android client that made the Web page (ii)

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.