Android uses HTML Design Interface

Source: Internet
Author: User

Android uses HTML Design Interface

Because the Android software development division is not yet refined, programmers often need to develop software interfaces. Although the software interface pictures have been designed by the artist, however, it is really difficult to use layout technology to make the software into a beautiful interface, but it is also time-consuming. Android uses WebView to implement the function of communication between JS Code and Java code, so that the interface development of Android software can also adopt the HTML web page technology, the majority of Web art artists can participate in the development of the Android software interface, so that programmers can be freed from it.

Project catalog

Main. xml


  
      
   
  

Index.html

<Script type = "text/javascript"> function show (jsondata) {// [{name: "xxx", amount: 600, phone: "13988888"}, {name: "bb", amount: 200, phone: "1398788"}] var jsonobjs = eval (jsondata); var table = document. getElementById ("personTable"); // find the personTable table for (var y = 0; y
Name Deposit Phone number
Refresh

Contact. java <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4NCjxwcmUgY2xhc3M9 "brush: java;"> package cn.itcast.domain;public class Contact { private Integer id; private String name; private String phone; private Integer amount; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPhone() { return phone; } public void setPhone(String phone) { this.phone = phone; } public Integer getAmount() { return amount; } public void setAmount(Integer amount) { this.amount = amount; } public Contact(Integer id, String name, String phone, Integer amount) { this.id = id; this.name = name; this.phone = phone; this.amount = amount; }}

ContactService. java

Package cn. itcast. service; import java. util. arrayList; import java. util. list; import cn. itcast. domain. contact; public class ContactService {/*** get Contact * @ return */public List
   
    
GetContacts () {List
    
     
Contacts = new ArrayList
     
      
(); Contacts. add (new Contact (12, "Zhang Ming", "13766666666", 13003); contacts. add (new Contact (23, "little", "130066006", 122003); contacts. add (new Contact (98, "Li xiaokai", "186768768", 10988787); contacts. add (new Contact (76, "Zhao De", "1565622566", 1666); return contacts ;}}
     
    
   

MainActivity. java

Package cn.itcast.html; import java. util. list; import org. json. JSONArray; import org. json. JSONException; import org. json. JSONObject; import cn. itcast. domain. contact; import cn. itcast. service. contactService; import android. app. activity; import android. content. intent; import android.net. uri; import android. OS. bundle; import android. webkit. webView; public class MainActivity extends Activity {private WebView webView; private ContactService contactService; @ Override public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. main); webView = (WebView) this. findViewById (R. id. webView); webView. loadUrl ("file: // android_asset/index.html"); webView. getSettings (). setJavaScriptEnabled (true); webView. addJavascriptInterface (new JSObject (), "contact"); // The js object is JSObject () and its name is contact contactService = new ContactService ();} private final class JSObject {public void call (String phone) {Intent intent = new Intent (Intent. ACTION_CALL, Uri. parse ("tel:" + phone); startActivity (intent);} public void showcontacts () {// [{name: "xxx", amount: 600, phone: "13988888" },{ name: "bb", amount: 200, phone: "1398788"}] try {List
   
    
Contacts = contactService. getContacts (); JSONArray jsonArray = new JSONArray (); for (Contact c: contacts) {JSONObject jsonObject = new JSONObject (); jsonObject. put ("name", c. getName (); jsonObject. put ("amount", c. getAmount (); jsonObject. put ("phone", c. getPhone (); jsonArray. put (jsonObject);} String json = jsonArray. toString (); webView. loadUrl ("javascript: show ('" + json + "')");} catch (JSONException e) {e. printStackTrace ();}}}}
   

Test Results

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.