常见控件如下:
1、TextView ---- 显示文本
2、EditText ---- 可编辑文本
3、Button ---- 按钮
4、Menu ---- 菜单
?
常用控件——RadioGroup、RadioButton、CheckBox、Toast
?
在布局文件中的配置格式如下:
<RadioGroup> <RadioButton/> <RadioButton/></RadioGroup><CheckBox/><CheckBox/><CheckBox/>
??
控件设置监听器代码如下:
?
//为RadioGroup设置监听器,需要注意的是,这里的监听器和Button控件的监听器有所不同genderGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { // TODO Auto-generated method stub if(femaleButton.getId() == checkedId){ System.out.println("famale"); //makeText()方法的第一参数是当前Activity类 Toast.makeText(RadioTest.this, "famle", Toast.LENGTH_SHORT).show(); } else if(maleButton.getId() == checkedId) { System.out.println("male"); } }}); //为多选按钮添加监听器swimBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub if(isChecked) { System.out.println("swim is checked"); } else { System.out.println("swim is unchecked"); } }});
?