由网友(谁跌撞了年少。)分享简介:我已经TimePicker对话和对话的DatePicker:I have made TimePicker Dialog and DatePicker Dialog:TimePicker对话框:TimePicker Dialog:public class TimePickerFragment extends Dia...
我已经TimePicker对话和对话的DatePicker:
I have made TimePicker Dialog and DatePicker Dialog:
TimePicker对话框:
TimePicker Dialog:
public class TimePickerFragment extends DialogFragment
implements TimePickerDialog.OnTimeSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current time as the default values for the picker
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
// Create a new instance of TimePickerDialog and return it
return new TimePickerDialog(getActivity(), this, hour, minute,
DateFormat.is24HourFormat(getActivity()));
}
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
// Do something with the time chosen by the user
}
}
DatePicker的对话框:
DatePicker Dialog:
public class DatePickerFragment extends DialogFragment
implements DatePickerDialog.OnDateSetListener {
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
// Create a new instance of DatePickerDialog and return it
return new DatePickerDialog(getActivity(), this, year, month, day);
}
public void onDateSet(DatePicker view, int year, int month, int day) {
// Do something with the date chosen by the user
}
}
我的问题是,当我选择时间或日期我想将其保存在特定的文本框。我该怎么办呢?
My problem is that when I pick time or date I want to save it in specific textField. How can I do it?
推荐答案
您可以将它设置回调方法onDateSet / onTimeSet。
You can set it callback method onDateSet/onTimeSet.
如果通过文本框,你的意思的TextView / EditText上你的XML布局。
If by textField, you mean textView/EditText in your xml layout.
((的TextView)findViewById(R.id.myTextField))的setText(FORMATTED_DATE);
有关格式,你可以做这样的事情。
For formatting, you can do something like this
String.format("%d-%d-%d",day,month,year)
东西艾克说
相关推荐
最新文章