Android第六天
来源:互联网 发布:如何申请淘宝网店 编辑:程序博客网 时间:2024/05/21 14:42
CheckBox控件
一、CheckBox属性
1.实现多选的控件
2.可设置初始状态是否被选中
android:checked=”true”
二、使用
1.初始化
<CheckBox android:id="@+id/checkBox1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:checked="true" android:text="吃火锅" /><CheckBox android:id="@+id/checkBox1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:checked="true" android:text="吃烧烤" /><CheckBox android:id="@+id/checkBox1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:checked="true" android:text="吃鸡" />private CheckBox checkBox1;checkBox1 = (CheckBox)findViewById(R.id.checkBox1);
2.设置监听器
checkBox1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { if(isChecked){ String text = checkBox1.getText().toString(); //获得CheckedBox的文本内容 Log.i("tag",text); } }});
3.效果
RadioGroup和RadioButton控件
一、RadioGroup是RadioButton的一个集合,提供多选一机制
二、属性
android:orientation=”vertical”——垂直排布
android:orientation=”horizontal”——水平排布
三、使用
1.将数个RadioButton放到同一个RadioGroup中,设置orientation为水平排布
<RadioGroup android:id="@+id/RadioGroup1" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content"><RadioButton android:id="@+id/radioButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:checked="true" android:text="男" /><RadioButton android:id="@+id/radioButton2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="女" /></RadioGroup>
2.初始化RadioButton并设置监听器
public class MainActivity extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener{ private RadioGroup rg; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); rg = (RadioGroup) findViewById(R.id.RadioGroup1); rg.setOnCheckedChangeListener(this); } @Override public void onCheckedChanged(RadioGroup radioGroup, @IdRes int checkedId) { switch (checkedId){ case R.id.radioButton1: Log.i("tag","man");break; case R.id.radioButton2: Log.i("tag","woman");break; } }}
3.效果
阅读全文
1 0
- Android第六天
- Android 第六天
- 学习android第六天
- Android基础第六天
- Android第六天
- Android第六天
- Android学习第六天-JDB
- Android基础第六天--线程
- android基础_第六天
- android开发第六天ContentProvider数据共享
- 我的android(第六天)
- Java -Android 学习(第六天)
- android开发第六天ContentProvider数据共享
- Android 第六天重置版_Activity
- Android 第六天重置版_Activity_注意事项
- 第六天 Android学习总结(Activity)
- Android第六天之Eclipse问题
- 第六天
- spark学习
- python 练习三
- MyEclipse+Tomcat+MAVEN+SVN项目完整环境搭建
- 小程序学习——第二篇app.json配置及tabBar示例
- ES6新语法
- Android第六天
- 安装测试
- python round函数并不是"四舍五入"
- 【Selenium专题】元素定位之CssSelector
- 637. Average of Levels in Binary Tree 104. Maximum Depth of Binary Tree
- 《星际特工》8.25内地公映 宇宙冒险颠覆视界
- Java内部类的使用小结 形参为什么要用final
- java中JOptionPane类的使用
- Mybatis dao传递参数为List时,需要注意的点