在设计单选按钮时,要根据实际情况对按钮进行分组,因为在同一组中的单选按钮只有一个能被选中。
在程序代码中实现要分别RadioGroup和RadioButton进行声明。
用findViewById()方法来取得对应控件的对象。
绑定监听器,注意:是对RadioGroup进行绑定,SetOnCheckedChangeListener(new…..)
java.lang.Object | ||||
↳ | android.view.View | |||
↳ | android.view.ViewGroup | |||
↳ | android.widget.LinearLayout | |||
↳ | android.widget.RadioGroup |
所以对于RadioGroup在布局文件xml中的属性依然有常见的:
android:id —-android.view.View
android:layout_width —-java.lang.Object
android:layout_height —-java.lang.Object
android:orientation —-android.widget.LinearLayout
java.lang.Object | |||||
↳ | android.view.View | ||||
↳ | android.widget.TextView | ||||
↳ | android.widget.Button | ||||
↳ | android.widget.CompoundButton | ||||
↳ | android.widget.RadioButton |
所以对于RadioButton在布局文件xml中的属性依然有常见的:
android:id —-android.view.View
android:layout_width —-java.lang.Object
android:layout_height —-java.lang.Object
android:text —- android.widget.TextView
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
接口 |
RadioGroup.OnCheckedChangeListener | 该接口定义一个回调函数,回调onCheckedChanged(RadioGroup group,int checkedId)方法,当radiobutton在这个组中被选中从而发生改变时被调用. |
Public Methods | ||
void |
setOnCheckedChangeListener(RadioGroup.OnCheckedChangeListener listener)对于这个RadioGroup绑定一个监听器,当radiobutton在这个组中被选中从而发生改变时被调用. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
java.lang.Object | |||||
↳ | android.view.View | ||||
↳ | android.widget.TextView | ||||
↳ | android.widget.Button | ||||
↳ | android.widget.CompoundButton | ||||
↳ | android.widget.CheckBox |
所以对于RadioGroup在布局文件xml中的属性依然有常见的:
android:id —-android.view.View
android:layout_width —-java.lang.Object
android:layout_height —-java.lang.Object
android:text —- android.widget.TextView
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
接口 |
CompoundButton.OnCheckedChangeListener | 该接口定义一个回调函数,回调onCheckedChanged(CompoundButton buttonView, boolean isChecked)方法,当Checkbox在这个组中被选中从而发生改变时被调用. |
Public Methods | ||
void |
setOnCheckedChangeListener(CompoundButton.OnCheckedChangeListener listener)对于这个CheckBox绑定一个监听器,当CheckBox被选中从而发生改变时被调用. |
在CompoundButton下有CheckBox, RadioButton, ToggleButton,对于RadioButton而言,是包含在RadioGroup群组下,
而且监听器是绑定在RadioGroup上,所以调用的是RadioGroup自身的监听接口。而CheckBox是在CompoundButton下,
且监听器是绑定在CheckBox自身上,所以调用的是CompoundButton中的监听接口。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
Toast是一种对用户的快速消息显示视图,当这种视图需要对用户显示是,会通过应用程序的浮动窗口形式来显示,
其浮动界面不接受焦点。有的时候用户可能会在指定输入的地方输入一些错误的信息,用户不一定轻易的察觉出来
应用程序就可以toast来提醒用户应该正确输入什么。
java.lang.Object | |
↳ | android.widget.Toast |
Public Methods | |
static Toast |
makeText(Context context, CharSequence text, int duration)Make a standard toast that just contains a text view. |
void |
show()Show the view for the specified duration. |
1 |
|