入力した情報を変数に入れる機能を追加しました。

This commit is contained in:
Ekamo-11 2024-06-12 16:45:09 +09:00
parent 895d9ceff5
commit efbd0703be
2 changed files with 72 additions and 8 deletions

View File

@ -1,10 +1,17 @@
package com.example.oplogy; package com.example.oplogy;
import static android.content.ContentValues.TAG;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.DialogFragment; import androidx.fragment.app.DialogFragment;
import android.annotation.SuppressLint;
import android.os.Bundle; import android.os.Bundle;
import android.app.TimePickerDialog; import android.app.TimePickerDialog;
import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.TextView; import android.widget.TextView;
import android.widget.TimePicker; import android.widget.TimePicker;
import java.util.Locale; import java.util.Locale;
@ -13,19 +20,68 @@ import java.util.Locale;
public class SetUpActivity extends FragmentActivity public class SetUpActivity extends FragmentActivity
implements TimePickerDialog.OnTimeSetListener { implements TimePickerDialog.OnTimeSetListener {
private TextView startTime; String teacherName;
private TextView endTime; String startPoint;
String startTime;
String endTime;
String breakTime;
int totalStudent;
private TextView setTeacherName;
private TextView setStartPoint;
private TextView setStartTime;
private TextView setEndTime;
private TextView setBreakTime;
private RadioButton setTenMinute;
private RadioButton setFifteenMinute;
private RadioButton setThirtyMinute;
private TextView setTotalStudent;
private Button setUp;
private boolean isStartTimeSelected = true; // デフォルトはstartTimeを選択 private boolean isStartTimeSelected = true; // デフォルトはstartTimeを選択
String startHourOfDay;
String startMinute;
String endHourOfDay;
String endMinute;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_set_up); setContentView(R.layout.activity_set_up);
startTime = findViewById(R.id.startTime); setTeacherName = findViewById(R.id.teacherName);
endTime = findViewById(R.id.endTime); setStartPoint = findViewById(R.id.startPoint);
setStartTime = findViewById(R.id.startTime);
setEndTime = findViewById(R.id.endTime);
setBreakTime = findViewById(R.id.breakTime);
setTenMinute = findViewById(R.id.tenMinute);
setFifteenMinute = findViewById(R.id.fifteenMinute);
setThirtyMinute = findViewById(R.id.thirtyMinute);
setTotalStudent = findViewById(R.id.totalStudent);
startTime.setOnClickListener(new View.OnClickListener() { setUp = findViewById(R.id.setUpButton);
setUp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
teacherName = setTeacherName.getText().toString();
Log.d(TAG, "Teacher Name: " + teacherName);
startPoint = setStartPoint.getText().toString();
Log.d(TAG, "Start Point: " + startPoint);
startTime = startHourOfDay + startMinute;
Log.d(TAG, "Start Time: " + startTime);
endTime = endHourOfDay + endMinute;
Log.d(TAG, "End Time: " + endTime);
breakTime = setBreakTime.getText().toString();
Log.d(TAG, "Break Time: " + breakTime);
totalStudent = Integer.parseInt(setTotalStudent.getText().toString());
Log.d(TAG, "onClick: できてるよ");
}
});
setStartTime.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
isStartTimeSelected = true; isStartTimeSelected = true;
@ -33,7 +89,7 @@ public class SetUpActivity extends FragmentActivity
} }
}); });
endTime.setOnClickListener(new View.OnClickListener() { setEndTime.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
isStartTimeSelected = false; isStartTimeSelected = false;
@ -42,14 +98,21 @@ public class SetUpActivity extends FragmentActivity
}); });
} }
@SuppressLint("DefaultLocale")
@Override @Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) { public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
String str = String.format(Locale.US, "%d:%d", hourOfDay, minute); // Textviewに保存する形式を設定 String str = String.format(Locale.US, "%d:%d", hourOfDay, minute); // Textviewに保存する形式を設定
if (isStartTimeSelected) { //押した場所を判定して押したほうにだけ挿入する if (isStartTimeSelected) { //押した場所を判定して押したほうにだけ挿入する
startTime.setText(str); startHourOfDay = String.format("%02d", hourOfDay);
startMinute = String.format("%02d", minute);
setStartTime.setText(str);
} else { } else {
endTime.setText(str); endHourOfDay = String.format("%02d", hourOfDay);
endMinute = String.format("%02d", minute);
setEndTime.setText(str);
} }
} }

View File

@ -132,6 +132,7 @@
android:gravity="center"/> android:gravity="center"/>
<RadioGroup <RadioGroup
android:id="@+id/timeInterval"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal" android:orientation="horizontal"