用java来布局activity(贴个代码),动态生成页面,(用WebView实现)
在 上一篇博客中[url]http://serryzhao.iteye.com/blog/873896 [/url] 动态生成了个很丑的页面,怎么让人家客户看啊
为了UI漂亮些,于是今天写了半天用WebView来实现了。
buf = new StringBuffer();buf.append("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>");buf.append("<html xmlns='http://www.w3.org/1999/xhtml'>");buf.append("<head><meta http-equiv='Content-Type' content='text/html; charset=utf-8' /><title>tab</title>" +"<style type='text/css'>table.tab {border-collapse:collapse;border-spacing:0;width:100%;color:#000;font-size:18px;}" +"table.tab input{width:200px; height:25px; font-size:16px;} table.tab th {text-align:right;padding:3px 0;}table.tab td {text-align:left;padding:3px 0;}</style></head>");buf.append("<script language='javascript'> function send2Android(){ " +" var car_type = '';var car_ad = ''; var car_ads = ''; var engine_no = '';var car_no = '';var car_discern = '';var record_no = '';var driver_no = '';" +"if(null!= document.getElementById('car_type')){car_type = document.getElementById('car_type').value;}" +"if(null != document.getElementById('car_ad')){" +"var temp = document.getElementById('car_ad'); " +"car_ad = document.getElementById('car_ad').value;" +"car_ads = temp[temp.selectedIndex].innerText; }" +"if(null != document.getElementById('car_no')){car_no = document.getElementById('car_no').value;}" +"if( null != document.getElementById('engine_no')){engine_no = document.getElementById('engine_no').value;}" +"if(null != document.getElementById('car_discern')){car_discern = document.getElementById('car_discern').value;}" +"if(null != document.getElementById('record_no')){record_no = document.getElementById('record_no').value;}" +"if(null != document.getElementById('driver_no')){driver_no = document.getElementById('driver_no').value;}" +" window.myjs.runOnAndroidJavaScript(car_type,car_ad,car_ads,car_no,engine_no,car_discern,record_no,driver_no) } </script> ");buf.append("<body><table class='tab'>");for(int i = 0; i<list.size();i++){String flag = list.get(i).getFlg();if("1".equals(flag)){buf.append("<tr><th>类型:</th>");buf.append("<td><select id='car_type'>");List<SelectBean> selectList = list.get(i).getList();for(int i1=0;i1<selectList.size();i1++){buf.append("<option value='" + selectList.get(i1).getId()+"'>"+selectList.get(i1).getName()+"</option>");}buf.append("</select></td></tr>");}else if("2".equals(flag)){buf.append("<tr><th>前缀:</th>");buf.append("<td><select id='car_ad'>");List<SelectBean> selectList = list.get(i).getList();for(int i1=0;i1<selectList.size();i1++){buf.append("<option value='" + selectList.get(i1).getId()+"'>"+selectList.get(i1).getName()+"</option>");}buf.append("</select></td></tr>");}else if("3".equals(flag)){buf.append("<tr><th>号:</th>");buf.append("<td><input type='text' name='textfield' id='car_no' /></td></tr>");}else if("4".equals(flag)){buf.append("<tr><th>号:</th>");buf.append("<td><input type='text' name='textfield2' id='engine_no' /></td></tr>");}else if("5".equals(flag)){buf.append("<tr><th>码:</th>");buf.append("<td><input type='text' name='textfield3' id='car_discern' /></td></tr>");}else if("6".equals(flag)){buf.append("<tr><th>号:</th>");buf.append("<td><input type='text' name='textfield4' id='record_no' /></td></tr>");}else if("9".equals(flag)){buf.append("<tr><th>号:</th>");buf.append("<td><input type='text' name='textfield5' id='driver_no' /></td></tr>");}}buf.append("</table></body></html>");webView.loadDataWithBaseURL(null, buf.toString(), "text/html", "UTF-8", null);
class runJavaScript{public void runOnAndroidJavaScript(final String car_type,final String car_ad,final String car_ads,final String car_no,final String engine_no,final String car_discern,final String record_no,final String driver_no){myHandler3.post( new Runnable() {@Overridepublic void run() {}});}}