Switch-RadioButton-CheckBox例子
来源:互联网 发布:mycat 性能优化 编辑:程序博客网 时间:2024/06/08 05:45
<span style="font-size: 18px; ">这里具体这么用我就不解释了,下面我就对他们做一个例子讲解</span>
public class MainActivity extends Activity {private RadioButton radio1,radio2,radio3;private CheckBox check;private Switch switch1;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);radio1=(RadioButton) findViewById(R.id.radio1);radio2=(RadioButton) findViewById(R.id.radio2);radio3=(RadioButton) findViewById(R.id.radio3);check=(CheckBox) findViewById(R.id.check);switch1=(Switch) findViewById(R.id.switch1);}public void radioClick(View v){RadioButton button=(RadioButton) v;boolean isChecked=button.isChecked();switch (v.getId()){case R.id.radio1:if(isChecked){Toast.makeText(MainActivity.this, button.getText(), Toast.LENGTH_LONG).show();}break;case R.id.radio2:if(isChecked){Toast.makeText(MainActivity.this, button.getText(), Toast.LENGTH_LONG).show();}break;case R.id.radio3:if(isChecked){Toast.makeText(MainActivity.this, button.getText(), Toast.LENGTH_LONG).show();}break;default:break;}}public void switchClick(View v){boolean isChecked=((Switch)v).isChecked();switch (v.getId()) {case R.id.switch1:if(isChecked){Toast.makeText(MainActivity.this, "打开", Toast.LENGTH_LONG).show();}else{Toast.makeText(MainActivity.this, "关闭", Toast.LENGTH_LONG).show();}break;default:break;}}public void checkClick(View v){CheckBox box=(CheckBox) v;boolean isChecked=box.isChecked();switch (v.getId()) {case R.id.check:if(isChecked){Toast.makeText(MainActivity.this, check.getText(), Toast.LENGTH_LONG).show();}break;default:break;}}}最后说下布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity" > <RadioGroup android:id="@+id/radioGroup1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> <RadioButton android:id="@+id/radio1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="radioClick" android:checked="true" android:text="男" /> <RadioButton android:id="@+id/radio2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="radioClick" android:text="女" /> <RadioButton android:id="@+id/radio3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="radioClick" android:text="保密" /> </RadioGroup> <Switch android:id="@+id/switch1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textOn="打开" android:textOff="关闭" android:onClick="switchClick" android:text="开启功能"/><CheckBox android:id="@+id/check" android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="checkClick" android:text="是否有用"/></LinearLayout>
这里是代码的连接:http://download.csdn.net/detail/kluing/7623545
0 0
- Switch-RadioButton-CheckBox例子
- CompoundButton之RadioButton、CheckBox、ToggleButton、Switch
- 设置ToggleButton、Switch、CheckBox和RadioButton的显示效果
- 设置ToggleButton、Switch、CheckBox和RadioButton的显示效果
- Android UI之选择器-ToggleButton、Switch、CheckBox和RadioButton
- 设置ToggleButton、Switch、CheckBox和RadioButton的区别
- Android之RadioButton与RadioGroup,CheckBox,Switch,ToggleButton的介绍
- Radiobutton、Checkbox
- Android学习笔记---第四天---基础UI组件---RadioButton&CheckBox&ToggleButton&Switch---Button的子类
- android开关按钮,Switch,ToggleButton,RadioButton,CheckBox ,多种实现开关按钮
- datagridview Checkbox 仿radiobutton
- RadioGroup RadioButton ,checkBox ,menu
- RadioButton和CheckBox
- checkbox,radiobutton事件练习
- RadioButton RadioGroup CheckBox
- RadioButton、CheckBox、AutoComplete
- CheckBox和RadioButton应用
- RadioButton和CheckBox浅析
- Column count doesn't match value count at row 1
- VS中向下取整Floor,向上取整ceil
- google code jam 2014 RC_D
- note3 使用
- 棋盘覆盖问题
- Switch-RadioButton-CheckBox例子
- Generate Parentheses
- UVa455 - Periodic Strings
- Oracle查询每个员工领导名称,要求显示结果为:员工号,员工姓名 员工领导名
- OpenCV安装VS版本问题
- mysql_store_result和mysql_use_result的区别
- NSData 日期 日期是由时间戳表示的,单位是秒
- linux内核地址空间
- strongswan ipsec 和思科 ASA5550 对接