1.radio时要用radiogroup
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/btnChooseTime"
android:layout_marginTop="55dp"
android:id="@+id/relativeLayout">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="A.印度洋"
android:id="@+id/rbA"
android:textAllCaps="false"
android:layout_alignParentLeft="true"
android:layout_marginLeft="0dp"
android:layout_alignParentTop="true"
android:layout_marginTop="0dp"
android:layout_gravity="center_horizontal" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="B.大西洋"
android:id="@+id/rbB"
android:layout_gravity="center_horizontal" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="提交"
android:id="@+id/btnSubmit"
android:layout_below="@+id/rbD"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal" />
</RadioGroup>
接口:
, DatePickerDialog.OnDateSetListener
, TimePickerDialog.OnTimeSetListener
启动日期,时间选择器
case R.id.btnChooseDate:
new DatePickerDialog(getActivity(),this,2015,3,10).show();//2015,3,10是打开时 显示的日期.
break;
case R.id.btnChooseTime:
new TimePickerDialog(getActivity(),this,0,0,true).show();//0.0是打开时的时间,trur是24小时格式
break;
接口实现:
/**
* @param view The view associated with this listener.
* @param year The year that was set.
* @param monthOfYear The month that was set (0-11) for compatibility
* with {@link Calendar}.
* @param dayOfMonth The day of the month that was set.
*/
@Override
//DatePickerDialog的回调
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
String s = String.format("%d-%d-%d",year,monthOfYear+1,dayOfMonth);
btnChooseDate.setText(s);
}
/**
* @param view The view associated with this listener.
* @param hourOfDay The hour that was set.
* @param minute The minute that was set.
*/
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
String s = String.format("%d:%d",hourOfDay,minute);
btnChooseTime.setText(s);
}
3.checkbox的接口
CompoundButton.OnCheckedChangeListener
回调函数
/**
* Called when the checked state of a compound button has changed.
*
* @param buttonView The compound button view whose state has changed.
* @param isChecked The new checked state of buttonView.
*/
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
<span style="white-space:pre"> </span>//...
}