0
我有DatePicker。如果我通過使用鍵盤更改值(年),則此值保持不變。只有當我點擊按鈕 「+」 或 「 - 」 值的變化.... 它我聽衆:
datePicker.init(year, month, day, new DatePicker.OnDateChangedListener() {
@Override
public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
mDate.set(Calendar.YEAR, year);
mDate.set(Calendar.MONTH, monthOfYear);
mDate.set(Calendar.DAY_OF_MONTH, dayOfMonth);
getArguments().putSerializable(EXTRA_DATE, mDate);
}
});
和類似的問題TimePicker(改變任何東西)
timePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {
@Override
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
mTime.set(Calendar.HOUR_OF_DAY, hourOfDay);
mTime.set(Calendar.MINUTE, minute);
getArguments().putSerializable(EXTRA_TIME, mTime);
}
})
和內部片段
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(resultCode != Activity.RESULT_OK) return;
if(requestCode == REQUEST_DATE){
Calendar date = (Calendar)data.getSerializableExtra(DateFragment.EXTRA_DATE);
mObject.setDate(date);
SimpleDateFormat dateFormat = new SimpleDateFormat("EE, dd.MM.yy", Locale.US);
mDateButton.setText(dateFormat.format(mObject.getDate().getTime()));
}
if(requestCode == REQUEST_TIME){
Calendar date = (Calendar)data.getSerializableExtra(TimeFragment.EXTRA_TIME);
mObject.setDate(date);
SimpleDateFormat dateFormat = new SimpleDateFormat("hh:mm, a", Locale.US);
mTimeButton.setText(dateFormat.format(mObject.getDate().getTime()));
}
}
在哪裏插入?我試過但getCurrentFocus無法解析方法...... –
你在對話框中使用它嗎? –
是的,我用在dialogFragment裏面... –