安卓 第三章 常用的控件
常用的控件,至少14种
TextView,Button,CheckBox,RadioButton, Spinner,SeekBar ,ProgressBar,RadioGroup,RadioButton,Switch,
Time,Date,GridLayout,LinearLayout,RelativeLayout,,FrameLayout,Listview,ScrollView,HorizontalScrollView,
SearchView,WebView,ImageView,ImageButton,Gallery,TimePicker,DatePicker,ImageSwitch,ViewFipper,ViewSwitch,
View,
checkbox
Android平台给我们提供了多选框的实现方法,每个多选框都是独立的,可以通过迭代所有多选框,然后根据它的状态是否要被选中再做出是否要获取它的值。
CheckBox类常用方法:
CheckBox.setChecked(true);将CheckBox设置成选中状态;
CheckBox.getText(); 获取多选框的值;
CheckBox.isChecked();判断该选项是否被选中;
调用setOnCheckedChangeListener()方法,处理多选框被选择事件,把CompoundButton.OnCheckedChangeListener实例作为参数传入。
RadioButton
Android平台中为我们提供了单选项的RadioGroup进行分组,在RadioGroup中定义若该个RadioButton选项。
RadioGroup用来对单选框进行分组的,相同组中的单选框只有一个单选框能被选中。常用到的方法如下:
RadioGroup.check(int id); 将指定的RadioButton设置成选中状态。
(RadioButton)findViewById(radioGroup.getCheckedRadioButtonId());获取被选中的单选框;
调用setOnCheckedChangListener()方法,处理单选框被选择事件,把RadioGroup.OnCheckedChangListener实例作为参数传入。
TextView
Imageview
ImageButtton
Spinner
switch
button
ToggleButton
ProgressBar