摘要:在本教程中,我们将向您展示如何创建文件中的个复选框,并论证了听者的使用检查选中或取消选中复选框的状态。这个项目是在开发,并与测试。。公共类延伸活动私人,,私人公共无效创建时的回调函数超级的。这,兄弟,尝试,。。新运行公共无效新。
在本教程中,我们将向您展示如何创建XML文件中的3个复选框,并论证了听者的使用检查–选中或取消选中复选框的状态。
P.S这个项目是在Eclipse 3.7开发,并与Android 2.3.3测试。
1。自定义字符串
Open “res/values/strings.xml” file, add some user-defined string.
res/values/strings.xml文件:
<resources>
<string 姓名=“hello“>Hello World, MyAndroidAppActivity!</string> <string 姓名=“app_name“>MyAndroidApp</string> <string 姓名=“chk_ios“>IPhone</string> <string 姓名=“chk_android“>Android</string> <string 姓名=“chk_windows“>Windows Mobile</string> <string 姓名=“btn_display“>Display</string>
</resources>
2。复选框
Open “res/layout/ main.xml” file, add 3 “复选框” and a button, inside the 线性布局.
文件:res/layout/ main.xml
<LinearLayout xmlns:android=“http://schemas.android.com/ap...“
安卓layout_width=“fill_parent“ 安卓layout_height=“fill_parent“ 安卓orientation=“vertical“ > <CheckBox 安卓id=“@+id/chkIos“ 安卓layout_width=“wrap_content“ 安卓layout_height=“wrap_content“ 安卓text=“@string/chk_ios“ > <CheckBox 安卓id=“@+id/chkAndroid“ 安卓layout_width=“wrap_content“ 安卓layout_height=“wrap_content“ 安卓text=“@string/chk_android“ 安卓checked=“true“ > <CheckBox 安卓id=“@+id/chkWindows“ 安卓layout_width=“wrap_content“ 安卓layout_height=“wrap_content“ 安卓text=“@string/chk_windows“ > <Button 安卓id=“@+id/btnDisplay“ 安卓layout_width=“wrap_content“ 安卓layout_height=“wrap_content“ 安卓text=“@string/btn_display“ >
</LinearLayout>
使复选框默认被选中
Put android:checked="true" inside checkbox element to make it checked bu default. In this case, “Android” option is checked by default.
三.代码代码
Attach listeners inside your activity “onCreate()” method, to monitor following events :
If checkbox id : “chkios” is checked, display a floating box with message “Bro, try Android”.
如果按钮被点击时,显示一个浮动框和复选框的状态显示。
文件:myandroidappactivity.java
旅行包 com。mkyong。android
进口 android。app。Activity
进口 android。os。Bundle
进口 android。view。View
进口 android。view。View。OnClickListener
进口 android。widget。Button
进口 android。widget。CheckBox
进口 android。widget。Toast
公共 类 myandroidappactivity 延伸 活动 {
私人 CheckBox chkIos, chkAndroid, chkWindows
私人 Button btnDisplay
@Override
公共 无效 创建时的回调函数(Bundle savedInstanceState) {
超级的。创建时的回调函数(savedInstanceState) setContentView(R。layout。main) addlisteneronchkios() addlisteneronbutton()
}
公共 无效 addlisteneronchkios() {
chkIos = (CheckBox) findViewById(R。id。chkIos) chkIos。setonclicklistener(新 onclicklistener() { @Override 公共 无效 onclick(View v) { / /是chkios检查吗? 如果 (((CheckBox) v)。把关()) { Toast。maketext(MyAndroidAppActivity。这, “兄弟,尝试Android:)”, Toast。LENGTH_LONG)。商展() } } })
}
公共 无效 addlisteneronbutton() {
chkIos = (CheckBox) findViewById(R。id。chkIos) chkAndroid = (CheckBox) findViewById(R。id。chkAndroid) chkWindows = (CheckBox) findViewById(R。id。chkWindows) btnDisplay = (Button) findViewById(R。id。btnDisplay) btnDisplay。setonclicklistener(新 onclicklistener() { clicked button is when /运行 @Override 公共 无效 onclick(View v) { StringBuffer result = 新 StringBuffer() result。追加(“iPhone检查:”)。追加(chkIos。把关()) result。追加(“nandroid检查:”)。追加(chkAndroid。把关()) result。追加(“移动nwindows检查:”)。追加(chkWindows。把关()) Toast。maketext(MyAndroidAppActivity。这, result。toString(), Toast.LENGTH_LONG).show(); } });
}
}
Run the application.
1. Result :
2. If “IPhone” is checked :
3. Checked “IPhone” and “Windows Mobile”, later, click on the “display” button :
原文地址:http://www.apkbus.com/blog-91...
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/14037.html
摘要:文件下的为根标签,属性和为指定了的命名空间,表示各种标准属性能在文件中使用和为标准的应用包名。元素下包含组件声明,包含四大组件。暂停状态失去焦点,但对用户可见,如弹窗。非活动状态被销毁,即退出应用。 问:达叔,你放弃了吗? 答:不,放弃是不可能的,丢了Android,你会心疼吗?如果别人把你丢掉,你是痛苦呢?还是痛苦呢?~ 引导语 有人说,爱上一个人是痛苦的,有人说,喜欢一个人是幸福的。...
摘要:一思考在移动端越来越重要的背景下,每位开发者对移动适配都有自己的想法。这个和移动端的设计体验方式是比较像的。对移动端的特殊性进行适配,如问题,默认样式等。 一、思考 在移动端越来越重要的背景下,每位web开发者对移动适配都有自己的想法。是移动优先,还是PC优先,还是两者兼得?在实际开发中这个问题是和项目产品定位有关的,也涉及到UI的设计,不是开发者能决定。但不管产品如何定位,作为开发...
摘要:一思考在移动端越来越重要的背景下,每位开发者对移动适配都有自己的想法。这个和移动端的设计体验方式是比较像的。对移动端的特殊性进行适配,如问题,默认样式等。 一、思考 在移动端越来越重要的背景下,每位web开发者对移动适配都有自己的想法。是移动优先,还是PC优先,还是两者兼得?在实际开发中这个问题是和项目产品定位有关的,也涉及到UI的设计,不是开发者能决定。但不管产品如何定位,作为开发...
摘要:上周经历了一场前所未有的挑战,因为自查应用网站暂停,在事情发生天内我们完成了自查,正式回归。以上为本周的更新日志,和以前一样,要表扬或者吐槽,随时联系我们 上周 fir.im 经历了一场前所未有的挑战,因为自查应用网站暂停,在事情发生4天内我们完成了自查,fir.im 正式回归。煎熬的 98 个小时,感谢开发者与用户对我们的信任和支持。 showImg(https://segmentf...
阅读 337·2021-10-09 09:44
阅读 1842·2021-09-02 15:41
阅读 3427·2019-08-30 15:53
阅读 1723·2019-08-30 15:44
阅读 1167·2019-08-30 13:10
阅读 912·2019-08-30 11:25
阅读 1293·2019-08-30 10:51
阅读 3252·2019-08-30 10:49