(iv) Android Webview in depth (bottom)

Source: Internet
Author: User

This article mainly introduces, how to add WebView in the ListView, and implement the drop-down refresh, the effect


Nonsense not much to say, the direct process:

1.mainActivity Layout file:

<span style= "FONT-SIZE:14PX;" ><relativelayout xmlns:android= "http://schemas.android.com/apk/res/android"    xmlns:tools= "http// Schemas.android.com/tools "    android:layout_width=" match_parent "    android:layout_height=" Match_parent "    tools:context= ". Mainactivity ">    <com.happy.demo.xlistview.xlistview        android:id=" @+id/xlv_list "        android:layout _width= "Fill_parent"        android:layout_height= "fill_parent"        android:background= "#f5f5f5"        android: Divider= "#00000000"        android:footerdividersenabled= "false"        android:headerdividersenabled= "false"        android:listselector= "#00000000" >    </com.happy.demo.xlistview.xlistview></relativelayout ></span>
2. mainactivity Main Interface Java code:

<span style= "FONT-SIZE:14PX;" >package com.happy.demo;import java.util.arraylist;import Java.util.list;import android.app.Activity;import Android.os.bundle;import Android.os.handler;import Com.happy.demo.adapter.myadapter;import Com.happy.demo.xlistview.xlistview;import Com.happy.demo.xlistview.xlistview.ixlistviewlistener;public Class Mainactivity extends Activity implements Ixlistviewlistener {private Xlistview xlv_list;private list<string> Lists = new arraylist<string> ();p rivate myadapter adapter; @Overrideprotected void OnCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); xlv_list = ( Xlistview) This.findviewbyid (r.id.xlv_list) lists.add ("http://www.qq.com"); adapter = new Myadapter (lists, Mainactivity.this); Xlv_list.setadapter (adapter); Xlv_list.setxlistviewlistener (this, 0); xlv_ List.setpullloadenable (false); Xlv_list.setrefreshtime ();} @Overridepublic void Onrefresh (int id) {new Handler (). postdelayed (New RunnablE () {@Overridepublic void run () {xlv_list.setrefreshtime (); Xlv_list.stoprefresh ();}}, 3000);} @Overridepublic void Onloadmore (int id) {//TODO auto-generated method stub}}</span>

3.adapter Adapter Item layout XML code:

<span style= "FONT-SIZE:14PX;" ><?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/ Res/android "    android:layout_width=" match_parent "    android:layout_height=" match_parent "    android:o rientation= "vertical" >    <webview        android:id= "@+id/wb_webview" android:layout_width= "Match_        Parent "        android:layout_height=" Match_parent "/></linearlayout></span>

4.adapter Adapter Java code:

<span style= "FONT-SIZE:14PX;" >package com.happy.demo.adapter;import java.util.list;import Com.happy.demo.r;import android.content.Context; Import Android.view.view;import Android.view.viewgroup;import Android.webkit.webview;import android.widget.baseadapter;/** * @author ZHONGLQ * @version V1.0 * @Date 2014-10-25 pm 10:53:37 */public class Myadapter ex Tends Baseadapter {private list<string> lists;private Context context;public myadapter (list<string> lists, Context context) {this.lists = Lists;this.context = Context;} @Overridepublic int GetCount () {return lists.size ();} @Overridepublic Object getItem (int position) {return lists.get (position);} @Overridepublic long Getitemid (int position) {return position;} @Overridepublic view GetView (int position, view Convertview, ViewGroup parent) {if (Convertview = = null) {Convertview = Vi Ew.inflate (context, r.layout.list_item, null);} WebView Wb_webview = (WebView) Convertview.findviewbyid (R.id.wb_webview); Setwebview (Lists.get (position), Wb_webview); return convertview;} private void Setwebview (String url, WebView WebView) {webview.loadurl (URL);}} </span>

This can be implemented in the ListView embedded WebView and implement the effect of the drop-down refresh, the code is not much, and compare understood, not much to explain.


(iv) Android Webview in depth (bottom)

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.