datePicker #40

Merged
Utahshi merged 11 commits from datePicker into master 2024-07-08 01:21:12 +00:00
Showing only changes of commit 01c3a27930 - Show all commits

View File

@ -175,9 +175,10 @@ public class SetUpActivity extends FragmentActivity
SharedPreferences sharedPreferences=getSharedPreferences("visitingDate",MODE_PRIVATE); SharedPreferences sharedPreferences=getSharedPreferences("visitingDate",MODE_PRIVATE);
SharedPreferences.Editor editor= sharedPreferences.edit(); SharedPreferences.Editor editor= sharedPreferences.edit();
editor.putString("day1",firstDay); //editorに値を渡す
editor.putString("day2",secondDay); editor.putString("day1",firstDay); //1日目
editor.putString("day3",thirdDay); editor.putString("day2",secondDay); //2日目
editor.putString("day3",thirdDay); //3日目
editor.apply(); editor.apply();
@ -186,8 +187,9 @@ public class SetUpActivity extends FragmentActivity
}); });
//DatePicker用
buttonFirstDay.setOnClickListener(v ->{ buttonFirstDay.setOnClickListener(v ->{
intIsDateSelected = 1; intIsDateSelected = 1; //ボタンの判別Date
showDatePickerDialog(); //DatePickerの表示 showDatePickerDialog(); //DatePickerの表示
}); });
@ -201,8 +203,9 @@ public class SetUpActivity extends FragmentActivity
showDatePickerDialog(); showDatePickerDialog();
}); });
//TimePicker用
buttonStartTimeButton.setOnClickListener(v -> { buttonStartTimeButton.setOnClickListener(v -> {
intIsStartTimeSelected = 1; //ボタンの判別 intIsStartTimeSelected = 1; //ボタンの判別Time
showTimePickerDialog(); //TimePickerの表示 showTimePickerDialog(); //TimePickerの表示
}); });
@ -251,8 +254,9 @@ public class SetUpActivity extends FragmentActivity
stringYear = String.valueOf(year); // stringYear = String.valueOf(year); //
stringMonth = String.format(Locale.JAPAN, "%02d", month + 1); // stringMonth = String.format(Locale.JAPAN, "%02d", month + 1); //
stringDayOfMonth = String.format(Locale.JAPAN, "%02d", dayOfMonth); // stringDayOfMonth = String.format(Locale.JAPAN, "%02d", dayOfMonth); //
firstDay = stringYear + stringMonth + stringDayOfMonth; firstDay = stringYear + stringMonth + stringDayOfMonth; //8桁の文字列を作成 )20240604
buttonFirstDay.setText(str); buttonFirstDay.setText(str); //buttonにformatされた文字列を挿入
} else if (intIsDateSelected == 2) { } else if (intIsDateSelected == 2) {
stringYear = String.valueOf(year); stringYear = String.valueOf(year);
stringMonth = String.format(Locale.JAPAN, "%02d", month + 1); stringMonth = String.format(Locale.JAPAN, "%02d", month + 1);
@ -277,10 +281,10 @@ public class SetUpActivity extends FragmentActivity
String str = String.format(Locale.JAPAN, "%02d:%02d", hourOfDay, minute); // Textviewに保存する形式を設定 String str = String.format(Locale.JAPAN, "%02d:%02d", hourOfDay, minute); // Textviewに保存する形式を設定
if (intIsStartTimeSelected == 1) { if (intIsStartTimeSelected == 1) {
stringHourOfDay = String.format("%02d", hourOfDay); stringHourOfDay = String.format("%02d", hourOfDay); //
stringMinute = String.format("%02d", minute); stringMinute = String.format("%02d", minute); //
startTime = stringHourOfDay + stringMinute; startTime = stringHourOfDay + stringMinute; //4桁の文字列を作成 0930
textViewStartTime.setText(str); textViewStartTime.setText(str); //textViewにformatされている文字列を挿入
} else if (intIsStartTimeSelected == 2) { } else if (intIsStartTimeSelected == 2) {
stringHourOfDay = String.format("%02d", hourOfDay); stringHourOfDay = String.format("%02d", hourOfDay);
@ -302,12 +306,12 @@ public class SetUpActivity extends FragmentActivity
} }
} }
private void showDatePickerDialog() { private void showDatePickerDialog() { //DatePickerDialogを表示する
DialogFragment newFragment = new DatePick(); DialogFragment newFragment = new DatePick();
newFragment.show(getSupportFragmentManager(), "datePicker"); newFragment.show(getSupportFragmentManager(), "datePicker");
} }
private void showTimePickerDialog() { // Dialogを表示する private void showTimePickerDialog() { // TimePickerDialogを表示する
DialogFragment newFragment = new TimePick(); DialogFragment newFragment = new TimePick();
newFragment.show(getSupportFragmentManager(), "timePicker"); newFragment.show(getSupportFragmentManager(), "timePicker");
} }