Android MVP mode for WebView history save and display

Source: Internet
Author: User

MVP on Android is a common design pattern, in the launhcer, mobile browser often see, observe the other great God wrote, now summed up, fencing up to write a demo

If you have any questions, please put them in the room.

We will study the discussion together.

Demo; http://download.csdn.net/detail/xufeifandj/8267619

Demo is mainly home page is a webview, realize the history of adding, and display. The example is relatively simple.

The entire project is structured as follows:




Historypresenter.java is primarily about the control of the view and model, which is equivalent to the control layer in MVC.

The specific implementation of the addition of historical records, such as the removal of the history of business logic, all in the Historymodel to achieve. And Ui.java is an interface, through the business logic analysis, the data to the UI to notify Mainacitivy update view.

Package Com.ferris.ferrismvp.presenter;import Java.util.list;import Com.ferris.ferrismvp.ui;import Com.ferris.ferrismvp.beam.history;import Com.ferris.ferrismvp.model.historymodel;import Com.ferris.ferrismvp.model.ihistorymodel;public class Historypresenter {private UI ui;private Ihistorymodel Ihistorymodel;public Historypresenter (UI UI) {//TODO auto-generated constructor stubthis.ui=ui;this.ihistorymodel= New Historymodel ();} /** * Add history * @param hisstring */public void addhistory (historical hisstring) {ihistorymodel.addhistory (hisstring);} /** * One off history * @param hisstring */public void removehistory (historical hisstring) {ihistorymodel.removehistory (hisstring);} /** * Show all history */public void Showhistorys () {list

History Model Business Logic interface, add delete, Query 3 methods.

Package Com.ferris.ferrismvp.model;import Java.util.list;import Com.ferris.ferrismvp.beam.history;public interface Ihistorymodel {public void addhistory;p ublic void removehistory (History);p ublic list< History>  showallhistory ();}


Concrete implementation Logic

Package Com.ferris.ferrismvp.model;import Java.util.arraylist;import Java.util.list;import Com.ferris.ferrismvp.beam.history;public class Historymodel implements Ihistorymodel{private list

History Bean Object

Package Com.ferris.ferrismvp.beam;public class History {private string Title;private string Url;public history () {//TODO Auto-generated Constructor Stub}public history (String title,string URL) {//TODO auto-generated constructor Stubthis.tit Le=title;this.url=url;} Public String GetTitle () {return title;} public void Settitle (String title) {this.title = title;} Public String GetUrl () {return URL;} public void SetUrl (String url) {this.url = URL;}}

UI Interface Classes

Package Com.ferris.ferrismvp;import Java.util.list;import Com.ferris.ferrismvp.beam.history;public interface UI { public void Showallhistory (list


Package Com.ferris.ferrismvp;import Java.util.list;import Com.ferris.ferrismvp.beam.history;import Com.ferris.ferrismvp.presenter.historypresenter;import Android.os.bundle;import Android.support.v7.app.actionbaractivity;import Android.view.view;import Android.view.View.OnClickListener; Import Android.webkit.webview;import Android.widget.button;import Android.widget.toast;public class MainActivity Extends Actionbaractivity implements Onclicklistener,ui{private WebView webView1;p rivate Button addhistory,    Showhistory;private Historypresenter Historypresenter;        @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);                Setcontentview (R.layout.activity_main);        Findview ();                Initwebview ();    Historypresenter=new Historypresenter (this);  } private void Initwebview () {//TODO auto-generated Method Stubwebview1.getsettings (). Setjavascriptenabled (True);  Webview1.loadurl ("http://www.baidu.com"); }private void Findview () {//TODO auto-generated method stubwebview1= (WebView) Findviewbyid (r.id.webview1); addhistory= (        button) Findviewbyid (R.id.button1), showhistory= (Button) Findviewbyid (R.id.button2);        Addhistory.setonclicklistener (this); Showhistory.setonclicklistener (this);} @Overridepublic void OnClick (View v) {//TODO auto-generated method Stubswitch (V.getid ()) {case r.id.button1://add history his Torypresenter.addhistory (New History (Webview1.gettitle (), Webview1.geturl ()); Break;case r.id.button2:// Show History Historypresenter.showhistorys (); break;default:break;}} @Overridepublic void Showallhistory (list



Android MVP mode for WebView history save and display

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.