android基础--采用HTML实现软件界面
来源:互联网 发布:linux cp命令详解 编辑:程序博客网 时间:2024/05/16 17:13
可以直接修改网页不用更新客户端
public class MainActivity extends Activity {
private WebView webView;
private ContactService contactService ;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
contactService = new ContactService();
webView = (WebView) this.findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);//使webView能支持js
webView.addJavascriptInterface(new JSObject(), "contact");
webView.loadUrl("file:///android_asset/index.html");//根据路径载入网页
}
private final class JSObject{
public void showContact(){
JSONArray jsonArray;
try {
List<Contact> contacts = contactService.getContacts();
jsonArray = new JSONArray();
for(Contact contact:contacts){
JSONObject jsonObject = new JSONObject();
jsonObject.put("name", contact.getName());
jsonObject.put("amount", contact.getAmount());
jsonObject.put("phone", contact.getPhone());
jsonArray.put(jsonObject);
String json = jsonArray.toString();
webView.loadUrl("javascript:show('"+json+"')");
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void call(String phone){
Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+phone));
startActivity(intent);
}
}
}
Index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
function show(jsondata){// "[{name:"xxx",amount:90,phone:"1339940444"},{name:"bbb",amount:90,phone:"1339940444"}]"
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].name;
td2.innerHTML = jsonobjs[y].amount;
td3.innerHTML = "<a href='javascript:contact.call(\""+ jsonobjs[y].phone+ "\")'>"+ jsonobjs[y].phone+ "</a>";
}
}
</script>
</head>
<!-- js代码通过webView调用其插件中的java代码 -->
<body onload="javascript:contact.showContact()">
<table border="0" width="100%" id="personTable" cellspacing="0">
<tr>
<td width="40%">姓名</td><td width="30%" align="center">存款额</td><td align="center">电话</td>
</tr>
</table>
<a href="javascript:window.location.reload()">刷新</a>
<img src="images/ss.gif" width="200"/>
</body>
</html>
一个javabean 。。。
一个service
public class ContactService {
public List<Contact> getContacts(){
List<Contact> contacts = new ArrayList<Contact>();
contacts.add(new Contact(22, "小A", "123",111111));
contacts.add(new Contact(22, "小b", "223",222222));
contacts.add(new Contact(22, "小c", "323",333333));
return contacts;
}
}
- android基础--采用HTML实现软件界面
- Android采用HTML设计软件界面webview
- Android采用HTML设计软件界面
- Android 采用HTML设计界面
- android基础--通过编码实现软件界面
- Android登陆界面采用文件存储实现
- 仲享登录界面html 采用table实现布局
- android编码实现软件界面
- Android编码实现软件界面
- android基础--采用方向传感器实现指南针
- Android中编码实现软件界面
- 界面HTML基础
- Android+Tomcat实现html解析基础
- html 设计android 界面
- Android中用html代码来实现界面 WebView控件
- android软件引导界面
- Android成长之路-编码实现软件界面
- Android应用开发之编码实现 软件界面
- Linux环境下的gcc命令
- 将P12/Pfx文件导入到支持CSP的硬件安全模块
- android基础--通过编码实现软件界面
- 若干时间后忘记的问题-----xp wince5.0 activesync 无法连接之记录
- IEBlog:在IE10下创建丰富的Text-Centric网页
- android基础--采用HTML实现软件界面
- ServletConfig的使用
- 通过URL读取文件内容
- Winform换肤原理
- android基础--国际化
- JAVA 入门: 手工编译并运行JAVA小程序
- C语言字符串格式化处理 sscanf函数
- 计算机精品学习资料大放送
- libpaxos阅读笔记