Android单选和多选择按钮
2010-10-12 02:13:00 来源:本站整理Android单选和多选择按钮:
Java代码
1. package mars.activity07;
2.
3. import android.app.Activity;
4. import android.os.Bundle;
5. import android.widget.CheckBox;
6. import android.widget.CompoundButton;
7. import android.widget.RadioButton;
8. import android.widget.RadioGroup;
9. import android.widget.Toast;
10.
11. public class RadioTest extends Activity {
12. /** Called when the activity is first created. */
13. //对控件对象进行声明
14. private RadioGroup genderGroup = null;
15. private RadioButton femaleButton = null;
16. private RadioButton maleButton = null;
17. private CheckBox swimBox = null;
18. private CheckBox runBox = null;
19. private CheckBox readBox = null;
20. @Override
21. public void onCreate(Bundle savedInstanceState) {
22. super.onCreate(savedInstanceState);
23. setContentView(R.layout.radio);
24. //通过控件的ID来得到代表控件的对象
25. genderGroup = (RadioGroup)findViewById(R.id.genderGroup);
26. femaleButton = (RadioButton)findViewById(R.id.femaleButton);
27. maleButton = (RadioButton)findViewById(R.id.maleButton);
28. swimBox = (CheckBox)findViewById(R.id.swim);
29. runBox = (CheckBox)findViewById(R.id.run);
30. readBox = (CheckBox)findViewById(R.id.read);
31. //为RadioGroup设置监听器,需要注意的是,这里的监听器和Button控件的监听器有所不同
32. genderGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
33.
34. @Override
35. public void onCheckedChanged(RadioGroup group, int checkedId) {
36. // TODO Auto-generated method stub
37. if(femaleButton.getId() == checkedId){
- ››Android 当修改一些代码时,使用什么编译命令可以最...
- ››Android 如何添加一个apk使模拟器和真机都编译进去...
- ››Android 修改Camera拍照的默认保存路径
- ››Android 如何修改默认输入法
- ››android开发中finish()和System.exit(0)的区别
- ››Android手势识别简单封装类
- ››android中查看项目数字证书的两种方法
- ››Android中获取IMEI码的办法
- ››android 相机报错 setParameters failed
- ››Android重启运用程序的代码
- ››Android为ListView的Item设置不同的布局
- ››android bitmap与base64字符串的互相转换
更多精彩
赞助商链接