私はジョーダタイムライブラリから日付をフェッチしています。私はdatepickerとtimpickerを使用してユーザーに日付と時刻を選択させています。私はそのボタンのonclick、datepickerが選択された日付をフェッチしてボタンに表示しますが、問題は、私がdatepickerを再び開くと、以前に選択されたものではなく、現在の日付と時刻が表示されます。私はdatepicker.ondatechangedリスナーを試してみましたが、動作するように見えるdoes notのjodatimeフェッチ日付とdatepickerダイアログon datechanged
@OnClick(R.id.Button_due_date)
public void show_DateTimePicker() {
final View dialogView = View.inflate(AddFollowUp.this, R.layout.datetime_picker, null);
final AlertDialog alertDialog = new AlertDialog.Builder(AddFollowUp.this).create();
dialogView.findViewById(R.id.date_time_set).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final DatePicker datePicker = (DatePicker) dialogView.findViewById(R.id.date_picker);
TimePicker timePicker = (TimePicker) dialogView.findViewById(R.id.time_picker);
DateTime dateTime_jodatime = new DateTime(
datePicker.getYear(),
datePicker.getMonth() + 1,
datePicker.getDayOfMonth(),
timePicker.getCurrentHour(),
timePicker.getCurrentMinute(),
0
);
mFollowUpTime =datePicker.getYear()+ "-";
if ((datePicker.getMonth() + 1) < 10) {
mFollowUpTime =mFollowUpTime+ "0" + (datePicker.getMonth() + 1) + "-";
} else
mFollowUpTime =mFollowUpTime+ (datePicker.getMonth() + 1) + "-";
if (datePicker.getDayOfMonth() < 10)
mFollowUpTime = mFollowUpTime + "0" + datePicker.getDayOfMonth()+ " ";
else
mFollowUpTime = mFollowUpTime + datePicker.getDayOfMonth() + " ";
if (timePicker.getCurrentHour() < 10)
mFollowUpTime = mFollowUpTime + "0" + timePicker.getCurrentHour() + ":";
else
mFollowUpTime = mFollowUpTime + timePicker.getCurrentHour() + ":";
if (timePicker.getCurrentMinute() < 10)
mFollowUpTime = mFollowUpTime + "0" + timePicker.getCurrentMinute();
else
mFollowUpTime = mFollowUpTime + timePicker.getCurrentMinute();
String month_text = dateTime_jodatime.monthOfYear().getAsText();
StringBuffer date = new StringBuffer();
date.append(dateTime_jodatime.getDayOfMonth() + " ");
date.append(month_text.substring(0, 3) + " ");
date.append(dateTime_jodatime.getYear() + " ");
date.append(dateTime_jodatime.getHourOfDay() + ":");
date.append(dateTime_jodatime.getMinuteOfHour() + "");
datePicker.updateDate(dateTime_jodatime.getYear(),dateTime_jodatime.getMonthOfYear(),dateTime_jodatime.getDayOfMonth());
String day = CommonUtils.AddZero(dateTime_jodatime.monthOfYear().get());
final String month = CommonUtils.AddZero(dateTime_jodatime.getDayOfMonth());
String year = CommonUtils.AddZero(dateTime_jodatime.getYear());
String hour = CommonUtils.AddZero(dateTime_jodatime.getHourOfDay());
String minute = CommonUtils.AddZero(dateTime_jodatime.getMinuteOfHour());
DonorDetails.Actual_Due_Date = day + "-" + month + "-" + year + " " + hour + ":" + minute + ":" + "00";
mButton_due_date.setText(date);
alertDialog.dismiss();
}
});
alertDialog.setView(dialogView);
alertDialog.show();
}
ここ
私のコードがあるが、私はまた、動作していないようdatepicker.updatedate機能を使用しようとしました。誰かが、日付ピッカーが選択した日付を2度目に表示する方法を教えてもらえますか?ここ
は、コードのための私のxmlです:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="8dp">
<DatePicker
android:id="@+id/date_picker"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4"
android:calendarViewShown="false"
android:spinnersShown="true" />
<TimePicker
android:id="@+id/time_picker"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4" />
<Button
android:id="@+id/date_time_set"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Set" />
誰もが解決策を提案してくださいことはできますか?
選択した日付と時刻を引数として渡して、表示する日付と時刻のピッカーを呼び出すメソッドとその値を使用して、選択した日付を設定することができます –
どうすればいいですか? –
を参照してください。http://www.tutorialspoint.com/android/android_datepicker_control.htm –