1. [代码]html代码     
<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <script type="text/javascript">
        function show(josndata){
            var jsonobjs = eval(jsondata);
            var table = document.getElementById("personTable");
            for(var y=0; y<jsonobjs.length; y++){
            var tr = table.insertRow(table.rows.length); //添加一行
            //添加三列
            var td1 = tr.insertCell(0);
            var td2 = tr.insertCell(1);
            td2.align = "center";
            var td3 = tr.insertCell(2);
            td3.align = "center";
            //设置列内容和属性
            td1.innerHTML = jsonobjs[y].id; 
            td2.innerHTML = jsonobjs[y].name; 
            td3.innerHTML = "<a href='javascript:itcast.call(\""+ jsonobjs[y].mobile+ "\")'>"+jsonobjs[y].mobile+"</a>"; 
            }
        }
    </script>
  </head>
    <!-- js代码通过webView调用其插件中的java -->
  <body onload="javascript:itcast.getContacts();">
    <table border="0" width="100%" id="personTable" cellpadding="0">
        <tr bgcolor="#E6F3FF"> 
            <td width="20%">编号</td>
            <td width="40%" align="center">姓名</td>
            <td align="center">电话</td>
        </tr>
    </table>
    <a href="javascript:window.location.reload()">刷新</a>
  </body>
</html>
2. [代码]静态赋值

package org.itcast.service;
 
import java.util.ArrayList;
import java.util.List;
 
import org.itcast.domain.Contact;
 
public class ContactService {
    public List<Contact> getContacts() throws Exception{
        List<Contact> contacts = new ArrayList<Contact>();
        contacts.add(new Contact(1,"xx","1254154741"));
        contacts.add(new Contact(2,"qq","548745141"));
        contacts.add(new Contact(21,"ss","13545874514"));
        return contacts;
         
    }
}
3. [代码]实体类

package org.itcast.domain;
 
public class Contact {
    private Integer id;
    private String name;
    private String moblie;
     
     
    public Contact() {
        super();
    }
     
     
    public Contact(Integer id, String name, String moblie) {
        super();
        this.id = id;
        this.name = name;
        this.moblie = moblie;
    }
 
 
    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 getMoblie() {
        return moblie;
    }
    public void setMoblie(String moblie) {
        this.moblie = moblie;
    }
     
     
}
4. [代码][Java]代码  
package org.itcast.ui;
 
import java.util.List;
 
import org.itcast.domain.Contact;
import org.itcast.service.ContactService;
import org.json.JSONArray;
import org.json.JSONObject;
http://www.huiyi8.com/hunsha/hanshi/​
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebView;
韩式婚纱照片 
public class HtmlUIActivity extends Activity {
    private WebView webView;
    private ContactService service;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        service = new ContactService();
        webView =(WebView)this.findViewById(R.id.webView);
        webView.getSettings().setJavaScriptEnabled(true);//打开js功能,使浏览器能使用脚本功能
        webView.addJavascriptInterface(new ContactPlugin(), "itcast");//为浏览器安装js插件,其中interfaceName表示是一个类名,调用js时都是interfaceName.xx();
        webView.loadUrl("file:///android_asset/index.html");
    }
    private class ContactPlugin{
        public void getContacts() throws Exception{
            List<Contact> contacts = service.getContacts();//得到联系人数据
            JSONArray array = new JSONArray();
            for (Contact contact :contacts) {
                JSONObject item = new JSONObject();
                item.put("id", contact.getId());
                item.put("moblie", contact.getMoblie());
                item.put("name", contact.getName());
                array.put(item);
            }
            String json = array.toString();//转成json字符串
            Log.i("HtmlUIActivity",json);
            webView.loadUrl("javascript:itcast.show('"+json+"')");
        }
        public void call(String moblie){
            Intent intent =new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+moblie));
            startActivity(intent);
        }
    }
}

调用html进行android布局的更多相关文章

  1. 转:Android布局优化

    categories: Android 在Android开发中,我们常用的布局方式主要有LinearLayout.RelativeLayout.FrameLayout等,通过这些布局我们可以实现各种各 ...

  2. Android 布局详解

    Android 布局详解 1.重用布局 当一个布局文件被多处使用时,最好<include>标签来重用布局. 例如:workspace_screen.xml的布局文件,在另一个布局文件中被重 ...

  3. Android布局优化:include 、merge、ViewStub的详细总结

    版权声明:本文出自汪磊的博客,未经作者允许禁止转载. 本篇博客主要是对上篇博客的补充Android性能优化之UI渲染性能优化, 没有什么新东西,觉得应该是都掌握的玩意,写出来也只是自己做个小小的总结. ...

  4. [旧][Android] 布局优化

    备注 原发表于2016.05.21,资料已过时,仅作备份,谨慎参考 前言 最近在编写布局时,发现这一块是有很多值得深入学习的地方的.毕竟应用开发,界面展示是十分重要的部分.另外在开发时,为自己的代码做 ...

  5. 【转】在Android布局中使用include和merge标签

    内容转自:http://fengweipeng1208.blog.163.com/blog/static/21277318020138229754135/ 在我们开发android布局时,经常会有很多 ...

  6. Android成长日记-Android布局优化

    Android常用布局 1. LinearLayout(线性布局) 2. RelativeLayout(相对布局) 3. TableLayout(表格布局) 4. AbsoluteLayou(绝对布局 ...

  7. 【转】Android布局优化之ViewStub

    ViewStub是Android布局优化中一个很不错的标签/控件,直接继承自View.虽然Android开发人员基本上都听说过,但是真正用的可能不多. ViewStub可以理解成一个非常轻量级的Vie ...

  8. Android 布局之LinearLayout

    Android 布局之LinearLayout 1 LinearLayout简介 LinearLayout是线程布局.它包括2个方向(android:orientation):“水平”(horizon ...

  9. Android 布局之RelativeLayout

    Android 布局之RelativeLayout 1 RelativeLayout简介 RelativeLayout是相对布局. RelativeLayout布局属性 1.1 与parent相对的属 ...

随机推荐

  1. 匿名块的四个类型(type rowtype record table)

    Oracle PL/SQL块 匿名块的四个类型 type rowtype record table ---- type (列类型)  %type类型是指声明变量的时候,参考某个表的某个列的类型---- ...

  2. BZOJ 3065 带插入区间第K小值

    题目描述 Description 从前有n只跳蚤排成一行做早操,每只跳蚤都有自己的一个弹跳力a[i].跳蚤国王看着这些跳蚤国欣欣向荣的情景,感到非常高兴.这时跳蚤国王决定理性愉悦一下,查询区间k小值. ...

  3. TSimpleMsgPack的样例代码

    TSimpleMsgPack的样例代码 unit uMain; interface uses SimpleMsgPack, Windows, Messages, SysUtils, Variants, ...

  4. ios 使用keychain具体方法

    Dictionary  写入: if ([self.currentUserAccount length] > 0) {                                Keycha ...

  5. [转]Go的50坑:新Golang开发者要注意的陷阱、技巧和常见错误-高级

    from : https://levy.at/blog/11 进阶篇 关闭HTTP的响应 level: intermediate 当你使用标准http库发起请求时,你得到一个http的响应变量.如果你 ...

  6. Direct2D教程(一)Direct2D已经来了,谁是GDI的终结者?

    什么是Direct2D 一言以蔽之,就是Windows 7平台上的一个2D图形API,可以提供高性能,高质量的2D渲染.大多数人对Direct2D可能都比较陌生,以至于我之前在论坛上提到这个词的时候, ...

  7. Linux 设备驱动开发 —— platform设备驱动应用实例解析

    前面我们已经学习了platform设备的理论知识Linux 设备驱动开发 —— platform 设备驱动 ,下面将通过一个实例来深入我们的学习. 一.platform 驱动的工作过程 platfor ...

  8. git 使用及常用命令

    git在团队项目中的使用流程 1.首先从一个git远程仓库中clone项目到本地 ? 1 git clone 仓库地址 2.创建开发分支 一般我们写代码不会在master分支上面写,而是新建一个分支 ...

  9. Ubuntu切换至root错误:su:Authentication failure解决

    当前用户切换到root出现这个错误的原因是没有创建root用户,解决如下: 1.打开终端,输入命令sudo passwd root 会提示输入新的用户密码,输入后会再确认一次,成功后会显示:passw ...

  10. openssl之EVP系列之11---EVP_Verify系列函数介绍

    openssl之EVP系列之11---EVP_Verify系列函数介绍     ---依据openssl doc/crypto/EVP_VerifyInit.pod翻译和自己的理解写成     (作者 ...