开发学院手机开发Android 开发 Android单选和多选择按钮 阅读

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 androi

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){

1 2 3 4 5  下一页

Tags:Android 单选 选择

编辑录入:爽爽 [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
更多精彩
    赞助商链接

    热点阅读
      焦点图片
        最新推荐
          精彩阅读