调用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相对的属 ...
随机推荐
- URAL - 1860 Fiborial
Discription Consider a sequence F i that satisfies the following conditions: Find the number of dif ...
- Android CrashHandler
package jason.android.utils; import android.content.Context; import android.content.pm.PackageInfo; ...
- Android NDK 环境配置
1. 下载NDK 官方链接地址: http://developer.android.com/tools/sdk/ndk/index.html 下载下来的应该是这个东西(以后可能会有更新,但步骤变动不会 ...
- MY JAVA-NOTE FIRST DAY
今天是第一天开通博客,我很开心,总算拥有了自己的博客了,以后我会经常在博客里分享一些JAVA的心得.
- 学习笔记 Java类的封装、继承和多态 2014.7.10
1.问题:toString()没搞懂? int a = 1; Integer aa = new Integer(a); //这是实现的过程 System.out.println("Hello ...
- VMware安装黑群暉5.2
选择典型就可以了,点击下一步. 选择 稍后安装操作系统,点击下一步. 客户机操作系统选择Linux,版本选择其他Linux2.6.x内核64位, 填写虚拟机名称和虚拟机文件保存位置的.填写好后点击 ...
- MySQL主从复制技术与读写分离技术amoeba应用
MySQL主从复制技术与读写分离技术amoeba应用 前言:眼下在搭建一个人才站点,估计流量会非常大,须要用到分布式数据库技术,MySQL的主从复制+读写分离技术.读写分离技术有官方的MySQL-pr ...
- Office 顿号怎么输
中文状态下回车上面一个按键就是
- Android Design Support Library概览
尊重劳动成果.转载请注明出处:http://blog.csdn.net/growth58/article/details/47972467 关注新浪微博:@于卫国 邮箱:yuweiguocn@gmai ...
- mt-checklist 的 bug 解疑 及 防止 this 指针偏移
1.今天在使用 mt-checklist 时,发现 绑定 change 方法后,第一次点击返回的值为 空数组 <template> <div id="app"&g ...