`
meohao
  • 浏览: 94862 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

写在20111011:checkbox的onClick事件

 
阅读更多
1.进入声音设置,勾选“选择操作音”;
2.勾选文件或文件夹时观察是否有选择操作音;
此时应该会对应的有选择操作音的,但为什么无选择操作音?
<CheckBox
   android:id="@+id/checkbox"
   android:layout_width="wrap_content"   
   android:layout_height="wrap_content"
   android:focusable="false">
</CheckBox> 

    原来SoundManager对于CheckBox的check事件不感冒,只对click事件产生作用,而对于CheckBox有setOnCheckedChangeListener的API,但是没有setOnClickListener,那CheckBox如何响应onClick事件呢?有一个属性可以在XML中可以配置。
CheckBox的API描述是这样的:
1.When the user selects a checkbox, the CheckBox object receives an on-click event.

To define the click event handler for a checkbox, add the android:onClick attribute to the <CheckBox> element in your XML layout. The value for this attribute must be the name of the method you want to call in response to a click event. The Activity hosting the layout must then implement the corresponding method.

2.The method you declare in the android:onClick attribute must have a signature exactly as shown above. Specifically, the method must:

•Be public
•Return void
•Define a View as its only parameter (this will be the View that was clicked)

故此时需要修改配置文件:
<CheckBox
   android:id="@+id/CheckBox"
   android:layout_width="wrap_content"   
   android:layout_height="wrap_content"
   android:focusable="false"
   android:onClick="sound">
</CheckBox> 

然后在加载该控件对应的配置文件的Activity中实现该函数,这里直接为空函数即可,注意这个函数必须是public权限,返回值为void,指定唯一参数View。
public void sound(View view){

}
OK,大功告成!此时勾选就可以听到清脆的勾选声了。

   但是在实际的项目中,由于编译选择的方式可能为user模式,此时user模式对编译进行了优化,该sound函数只是一个空函数,在编译检查的时候发现其未被调用,就直接被优化掉了,在sound函数加一行Log编译不同的user和eng版本,查看是否有Log输出,就可以知道了,那优化掉了,这里点击checkbox此时就会报错,因为找不到该函数。
   解决方法,在编译.mk文件中添加下列语句将优化禁用掉,再编译任何模式的版本就不会有问题了。
   LOCAL_PROGUARD_ENABLED :=disabled
分享到:
评论

相关推荐

    设置checkbox为只读(readOnly)的两种方式

    方式一: checkbox没有readOnly属性,如果使用disabled=“disabled”属性的话,会让checkbox变成灰色的,用户很反感这种样式可以这样让它保持只读: 设置它的onclick=”return false” js里就是 checkbox.onclick=...

    Html\checkbox)属性解析及应用.docx

    Html 中的复选框(Checkbox)属性解析及应用 Html 中的复选框(Checkbox)是一种常用的表单控件,...在上面的例子中,我们使用了 Checkbox 来实现多选框的功能,并使用了 onclick 事件来实现选中和取消选中的功能。

    asp.net checkbox 动态绑定id GridView删除提示

    ’ type=”checkbox” onclick=”return Click()”/&gt; GridView删除提示 代码如下:”del” xss=removed&gt;删除&lt;/div&gt; 您可能感兴趣的文章:DataGridView中CheckBox实现某一列单选Gridview使用CheckBox全选与单选采用js...

    gridview checkbox 全选

    &lt;input id="cbAll" type="checkbox" onclick="GetAllCheckBox(this)" /&gt;全选 function GetAllCheckBox(CheckAll) { var items = document.getElementsByTagName("input"); for(i=0; i;i++) { if(items[i]....

    关于onchange事件在IE和FF下的表现及解决方法

    在最近做的一个项目中,有这么一个功能点:页面上有一个checkbox,当用户选择或者取消选择该checkbox时会向后台发一个jsonp请求。当时的实现是为这个checkbox...为了解决这个问题,我在checkbox的onclick事件里添加了

    ztree树节点前面有checkbox

    &lt;TITLE&gt; ZTREE DEMO - checkbox ; charset=UTF-8"&gt; &lt;script type="text/javascript" src="jquery-1.4.4.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="jquery.ztree.core.js"&gt;&lt;/script&gt; ...

    复选框相关代码

    &lt;input type="checkbox" id="chk_SelectAll" onclick="javascript:onSelectAll(this.checked);" /&gt; 循环的框 &lt;input id="screenNumber" type="checkbox" name="checkbox" runat="server" nname='Id' value='("screen...

    jquery应该如何来设置改变按钮input的onclick事件

    jquery应该如何来设置按钮input的onclick事件?比如开始时有个按钮: &lt;input id=”prebt” type=”button” value=”上一页” onclick=”ToPage(2)”/&gt;这行代码是在程序后台生成的,和Discuz!NT论坛源码中的...

    javaScript常用事件

    注意:此事件写在方法的外面,且函数名(方法名)后不加括号!例:window.onscroll=move; 4.onBlur失去焦点事件:当光标离开文本框是触发调用函数。 当text对象或textarea对象以及select对象不再拥有焦点、而退到...

    基于JS实现checkbox全选功能实例代码

    此功能经常会用户,下面小编给大家分享下实现代码,一起看看吧! 效果图如下: ...input type="checkbox" onclick="quanxuan()"&gt;全选 &lt;input type="checkbox" name="nation"&gt;唱歌 &lt;input type

    项目开发asp.net

    asp.net项目开发学校毕业作业 ... &lt;asp:TextBox ID="TextBox1" runat="server"&gt;&lt;/asp:TextBox&gt; ... &lt;asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="登录" /&gt; &lt;/html&gt;

    asp.net在线考试系统

    If CheckBoxList2.Items(0).Selected = False And CheckBoxList2.Items(1).Selected = False And CheckBoxList2.Items(2).Selected = True And CheckBoxList2.Items(3).Selected = False And CheckBoxList2.Items(4...

    javascript中checkbox使用方法简单实例演示

    演示一个小小的例子:在购物车里面,我们能够勾选自己所选的商品,然后能够显示出相应的价格。 1、首先显示出相应的界面:   相关代码: &lt;body&gt; 商品列表: 笔记本电脑&lt;input type="checkbox" ...

    GridView中加上CheckBox 的全选功能的代码

    首先我們當然是要先做出一個有資料的GridViewGridView做好後,我們在後方新增一個樣板欄位(TemplateField)請在新增的樣板欄位中的HeaderTemplate加入一個CheckBox作為全選用,然後在ItemTemplate也加入一個CheckBox ...

    jquery动态改变onclick属性导致失效的问题解决方法

    onclick属性失效的问题,相信很多的朋友都有遇到过吧,jquery动态改变onclick属性就会导致此问题的发生,解决方法如下,希望对大家有所帮助

    input checkbox 扩大点击范围的实现方法

    input type=checkbox onclick=All_None(this.checked) style=width:100%;height:100%;&gt;  设置宽高度为100%. 以上这篇input checkbox 扩大点击范围的实现方法就是小编分享给大家的全部内容了,希望能给大家一...

    jQuery实现table表格checkbox全选的方法分析

    本文实例讲述了jQuery实现table表格checkbox全选的方法。分享给大家供大家参考,具体如下: 今天在页面中使用jQuery实现了全选框操作,如图...input type="checkbox" onclick="selectAll(this.checked)" /&gt; &lt;/tr&gt;

    jquery数组之存放checkbox全选值示例代码

    input type=”checkbox” id=”checkAll” value=”1″&gt;全选/全部不选 &lt;input type=”checkbox” name=”items” value=”1″&gt;1 &lt;input type=”checkbox” name=”items” value=”2″&gt;2 &lt;input ...

    ASP.NET Gridview与checkbox全选、全不选实现代码

    1. 页面 在onclick事件中 “传自己” 代码如下: ”全选”&gt; &lt;HeaderTemplate&gt; &lt;input type=”checkbox” id=”CheckBox1″ name=”CheckBox1″ onclick=”GetAllCheckBox(this)” /&gt; 全选 &lt;/HeaderTemplate&gt; ...

    浅析jquery与checkbox的checked属性的问题

    2、checkbox里的onchange或onclick方法里用jquery的attr方法获取checked是看得到的checked属性的值与它是否给钩上没有关系 3、使用document.getElementById(“checkbox_id”).checked获取的值与是否钩上一至,即与...

Global site tag (gtag.js) - Google Analytics