调用html进行android布局
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布局的更多相关文章
- 转:Android布局优化
categories: Android 在Android开发中,我们常用的布局方式主要有LinearLayout.RelativeLayout.FrameLayout等,通过这些布局我们可以实现各种各 ...
- Android 布局详解
Android 布局详解 1.重用布局 当一个布局文件被多处使用时,最好<include>标签来重用布局. 例如:workspace_screen.xml的布局文件,在另一个布局文件中被重 ...
- Android布局优化:include 、merge、ViewStub的详细总结
版权声明:本文出自汪磊的博客,未经作者允许禁止转载. 本篇博客主要是对上篇博客的补充Android性能优化之UI渲染性能优化, 没有什么新东西,觉得应该是都掌握的玩意,写出来也只是自己做个小小的总结. ...
- [旧][Android] 布局优化
备注 原发表于2016.05.21,资料已过时,仅作备份,谨慎参考 前言 最近在编写布局时,发现这一块是有很多值得深入学习的地方的.毕竟应用开发,界面展示是十分重要的部分.另外在开发时,为自己的代码做 ...
- 【转】在Android布局中使用include和merge标签
内容转自:http://fengweipeng1208.blog.163.com/blog/static/21277318020138229754135/ 在我们开发android布局时,经常会有很多 ...
- Android成长日记-Android布局优化
Android常用布局 1. LinearLayout(线性布局) 2. RelativeLayout(相对布局) 3. TableLayout(表格布局) 4. AbsoluteLayou(绝对布局 ...
- 【转】Android布局优化之ViewStub
ViewStub是Android布局优化中一个很不错的标签/控件,直接继承自View.虽然Android开发人员基本上都听说过,但是真正用的可能不多. ViewStub可以理解成一个非常轻量级的Vie ...
- Android 布局之LinearLayout
Android 布局之LinearLayout 1 LinearLayout简介 LinearLayout是线程布局.它包括2个方向(android:orientation):“水平”(horizon ...
- Android 布局之RelativeLayout
Android 布局之RelativeLayout 1 RelativeLayout简介 RelativeLayout是相对布局. RelativeLayout布局属性 1.1 与parent相对的属 ...
随机推荐
- Java中Javadoc的{@link}与@see的简单区别
{@link}与@see这两个Javadoc注解都可以直接链接类和方法.用法基本一致. 但是@see必须顶头写,而{@link可以任意地方},如下所示: 参考: http://blog.csdn.ne ...
- SpringBoot中@EnableAutoConfiguration注解用法收集
参考: http://blog.csdn.net/xiaoyu411502/article/details/52770723 https://docs.spring.io/spring-boot/do ...
- AndroidStudio怎样导入jar包
来自:http://jingyan.baidu.com/article/e6c8503c7190b7e54f1a1893.html AndroidStudio用于开发安卓Apk非常地方便,但是它的很多 ...
- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
一.背景 最近的项目在用maven 进行install的时候,发现老师在控制台输出警告:[WARNING] Using platform encoding (UTF-8 actually) to co ...
- 自定义PropertyGrid控件【转】
自定义PropertyGrid控件 这篇随笔其实是从别人博客上载录的.感觉很有价值,整理了一下放在了我自己的博客上,希望原作者不要介意. 可自定义PropertyGrid控件的属性.也可将属性名称显示 ...
- android-BroadcastReceive广播接收器
应用可以使用它对外部事件进行过滤,只对感兴趣的外部事件(如当电话呼入时,或者数据网络可用时)进行接收并做出响应.广播接收器没有用户界面.然而,它们可以启动一个activity或service来响应它们 ...
- SGPIO
http://en.wikipedia.org/wiki/SGPIO SGPIO From Wikipedia, the free encyclopedia Serial General Purp ...
- mongodb3.0 性能測试报告 二
mongodb3.0 性能測试报告 一 mongodb3.0 性能測试报告 二 mongodb3.0 性能測试报告 三 測试环境: 服务器:X86 pcserver 共6台 cpu: 单颗8核 ...
- 几篇QEMU/KVM代码分析文章
QEMU/KVM结合起来分析的几篇文章,代码跟最新的版本有些差异,但大体逻辑一样,写得通俗易懂.我把链接放这里主要是为自己需要查看时调转过去方便,感谢作者的付出! QEMU Source Code S ...
- php返回HTTP状态码
HTTP协议状态码,调用函数时候只需要将$num赋予一个下表中的已知值就直接会返回状态了.<?PHP /** * HTTP Protocol defined status codes* HTTP ...