
看了看方法,有四个,onConfigurationChanged(Configuration newConfig),onCreate(),onLowMemory(),onTerminate()。大概看了下下,做了下试验,只懂了一个onCreate(),它比入口Activity的onCreate()先初始化,应该也就是which will cause that class to be instantiated for you when the process for your application/package is created.不多说了,贴代码吧。
自定义的Application,定义了两个变量,字符串变量params及一个Actitvity:
[java] view plain copy
package com.ghli.applicationtest
import android.app.Application
import android.util.Log
public class MyApplication extends Application {
private static final String TAG = "MyApplication"
//自定义的变量
private String param1
private ApplicationTest firstAct
public String getParam1() {
return param1
}
public void setParam1(String param1) {
this.param1 = param1
}
public ApplicationTest getFirstAct() {
return firstAct
}
public void setFirstAct(ApplicationTest firstAct) {
this.firstAct = firstAct
}
@Override
public void onCreate() {
super.onCreate()
Log.v(TAG, "onCreate")
}
}
实现这个功能的方法很多,如果用javascript的话,可以这样:在页面的<asp:panel></asp:panel>这个标签里添加一个<Div></Div>,div中将label控件包含进去;在Button1的客户端的click中写个函数,复制页面元素,主要是应用javascript的cloneNode方法,可以查找网上资料,这个方法不需要刷新页面,速度快。
方法二:
你这样做未必就没有添加label,你可以在点击一次按钮后,在页面上看它的html代码,调试一下错误所在,看页面上是否会有两个label标签。
代码如下,只是示例:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default6.aspx.cs" Inherits="Default6" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script type="text/javascript">
function insertMessage() {
if(document.getElementsByTagName("tbody").length<16) {
var oNewNode = document.getElementById("ass").firstChild.cloneNode(true)
document.getElementById("ass").appendChild(oNewNode)
} else {
alert("最多只能同时上传10个附件!")
return false
}
}
function moveMessage() {
if(document.getElementsByTagName("tbody").length>3){
var oOldNode = document.getElementById("ass").lastChild
oOldNode.parentNode.removeChild(oOldNode)
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table><tr><td>
上传附件:<a href="###" onclick="insertMessage()">[+]</a><a href="###" onclick="moveMessage()">
[-]</a>
<table id="ass">
<tr>
<td style="height: 22px">
附件:<asp:FileUpload unselectable="on" ID="filePost" runat="server" /></td>
</tr>
</table></td></tr>
</table>
</div>
</form>
</body>
</html>
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)