星空网 > 软件开发 > ASP.net

第5章(4) 单选和复选

分类:C#、Android、VS2015;

创建日期:2016-02-07

一、简介

1、CheckBox

复选

【Checked】属性:是否选中。

2、RadioButton

单选

【Checked】属性:是否选中。

【RadioGroup】属性:RadioButton的分组容器。注意必须将RadioButton包含在RadioGroup内。

二、示例4—Demo04CheckBoxRadioButton

1、运行截图

第5章(4) 单选和复选

2、添加demo04_CheckBoxRadioButton.a在layout文件夹下添加该文件。

从【工具箱】中向设计界面拖放2个【CheckBox】控件,1个【RadioGroup】控件,然后直接在【源】中将其修改为下面的内容:

<??><LinearLayout ="http://schemas.android.com/apk/res/android"  android:orientation="vertical"  android:layout_width="match_parent"  android:layout_height="match_parent">  <CheckBox    android:text="红色"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:id="@+id/checkBoxRed" />  <CheckBox    android:text="绿色"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:id="@+id/checkBoxGreen" />  <RadioGroup    android:minWidth="25px"    android:minHeight="25px"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:id="@+id/radioGroupGander">    <RadioButton      android:layout_width="wrap_content"      android:layout_height="wrap_content"      android:checked="true"      android:text="男"      android:id="@+id/radioButtonMale" />    <RadioButton      android:layout_width="wrap_content"      android:layout_height="wrap_content"      android:text="女"      android:id="@+id/radioButtonFamale" />  </RadioGroup>  <Button    android:id="@+id/btnOK"    android:layout_width="fill_parent"    android:layout_height="wrap_content"    android:text="确定" /></LinearLayout>

3、添加Demo04CheckBoxRadioButton.cs文件

在SrcActivity文件夹下添加该文件。

using System;using Android.App;using Android.OS;using Android.Widget;namespace ch05demos.SrcActivity{  [Activity(Label = "CheckBoxRadioButtonDemo")]  public class Demo04CheckBoxRadioButton : Activity  {    CheckBox red, green;    RadioButton nan, nv;    protected override void OnCreate(Bundle savedInstanceState)    {      base.OnCreate(savedInstanceState);      SetContentView(Resource.Layout.demo04_CheckBoxRadioButton);      red = FindViewById<CheckBox>(Resource.Id.checkBoxRed);      green = FindViewById<CheckBox>(Resource.Id.checkBoxGreen);      nan = FindViewById<RadioButton>(Resource.Id.radioButtonMale);      nv = FindViewById<RadioButton>(Resource.Id.radioButtonFamale);      var button = FindViewById<Button>(Resource.Id.btnOK);      button.Click += Button_Click;    }    private void Button_Click(object sender, EventArgs e)    {      string s1 = "性别:" + (nan.Checked ? "男" : "女");      string s2 = "喜欢的颜色:";      if (red.Checked) s2 += red.Text;      if (green.Checked) s2 += " " + green.Text;      Toast.MakeText(this,        string.Format("{0}\n{1}", s1, s2),        ToastLength.Long).Show();    }  }}

运行观察该例子的效果。

提示:通过【Checked】属性或Toggle()方法都可以改变RadioButton的状态。


原标题:第5章(4) 单选和复选

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

Inventory PlannerI:https://www.goluckyvip.com/tag/21566.html
Inventory Spy:https://www.goluckyvip.com/tag/21568.html
InventoryLab:https://www.goluckyvip.com/tag/21569.html
listing乱码:https://www.goluckyvip.com/tag/2157.html
Investree:https://www.goluckyvip.com/tag/21570.html
INVIMA:https://www.goluckyvip.com/tag/21571.html
黄果树瀑布景区景点 - 黄果树瀑布景区景点分布图:https://www.vstour.cn/a/408258.html
延边酒店(附近旅馆住宿50元):https://www.vstour.cn/a/409226.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流