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. mybatis 源码学习(一)配置文件初始化

    mybatis是项目中常用到的持久层框架,今天我们学习下mybatis,随便找一个例子可以看到通过读取配置文件建立SqlSessionFactory,然后在build拿到关键的sqlsession,这 ...

  2. git pull出现fatal: unable to access 'https://github.com/XXX/YYY.git'

    用cmd 发现ping不同 github.com Ping不通,这时候,只需要在host文件里做些修改就可以,首先,定位到路径 C:\Windows\System32\drivers\etc 找到ho ...

  3. 无向图的点双连通分量(tarjan模板)

    #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #i ...

  4. 金山面试CDN

    History 今天去金山网络面试的时候,被问到性能优化,我说了几个.最后说到了CDN,我说要尽量把静态的内容放置到CDN,可是为什么呢?面试官说既然你说到CDN.你就说说它的原理. 之前有看过,可是 ...

  5. java中Volatile修饰符的含义

    在java语言中:为了获得最佳速度,同意线程保存共享成员变量的私有拷贝.并且仅仅当线程进入或者离开同步代码块时才与共享成员变量的原始值进行对照. volatilekeyword的作用就是提示vm:对于 ...

  6. 用 Sencha Touch 构建移动 web 应用程序

    Sencha Touch 是一个使用 HTML5.CSS3 和 JavaScript 语言构建的移动 web 应用程序框架,在本文中,学习如何应用您当前的 web 开发技能进行移动 web 开发.下载 ...

  7. mysql报错锦集

    MySQL 启动报错 - ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/ ...

  8. enter键触发的函数

    enter键触发的函数示例: <input type="text" onkeydown="fun();"> function fun() { if( ...

  9. do export method of oracle all database tables with dmp files.

    usually we need to export the database tables to backup and others use. So we must know what to do e ...

  10. bootstrap table api

    http://blog.csdn.net/rickiyeat/article/details/56483577