開始時刻と、終了時刻をクリックすると選択した時間が挿入される機能を作成しました。ただ両方の時刻とも挿入されるので、修正します
This commit is contained in:
parent
afa4b678e0
commit
2d17a13d3b
|
@ -1,14 +1,43 @@
|
|||
package com.example.oplogy;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import android.os.Bundle;
|
||||
import android.app.TimePickerDialog;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import android.widget.TimePicker;
|
||||
import java.util.Locale;
|
||||
|
||||
public class SetUpActivity extends AppCompatActivity {
|
||||
|
||||
public class SetUpActivity extends FragmentActivity
|
||||
implements TimePickerDialog.OnTimeSetListener {
|
||||
|
||||
private TextView startTime;
|
||||
private TextView endTime;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_set_up);
|
||||
|
||||
startTime = findViewById(R.id.startTime);
|
||||
endTime = findViewById(R.id.endTime);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
|
||||
|
||||
String str = String.format(Locale.US, "%d:%d", hourOfDay, minute);
|
||||
|
||||
startTime.setText(str);
|
||||
endTime.setText(str);
|
||||
|
||||
}
|
||||
|
||||
public void showTimePickerDialog(View v) {
|
||||
DialogFragment newFragment = new TimePick();
|
||||
newFragment.show(getSupportFragmentManager(), "timePicker");
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
package com.example.oplogy;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
public class SetupActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.setup);
|
||||
}
|
||||
}
|
30
app/src/main/java/com/example/oplogy/TimePick.java
Normal file
30
app/src/main/java/com/example/oplogy/TimePick.java
Normal file
|
@ -0,0 +1,30 @@
|
|||
package com.example.oplogy;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import android.app.Dialog;
|
||||
import android.app.TimePickerDialog;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.widget.TimePicker;
|
||||
import java.util.Calendar;
|
||||
|
||||
public class TimePick extends DialogFragment implements
|
||||
TimePickerDialog.OnTimeSetListener{
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
final Calendar c = Calendar.getInstance();
|
||||
int hour = c.get(Calendar.HOUR_OF_DAY);
|
||||
int minute = c.get(Calendar.MINUTE);
|
||||
|
||||
return new TimePickerDialog((Context) getActivity(),
|
||||
(TimePickerDialog.OnTimeSetListener) getActivity(), hour, minute, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
|
||||
|
||||
}
|
||||
}
|
|
@ -79,6 +79,7 @@
|
|||
android:id="@+id/startTime"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="showTimePickerDialog"
|
||||
android:autofillHints=""
|
||||
android:inputType=""
|
||||
tools:ignore="LabelFor"/>
|
||||
|
@ -102,6 +103,7 @@
|
|||
android:id="@+id/endTime"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="showTimePickerDialog"
|
||||
android:autofillHints=""
|
||||
android:inputType=""
|
||||
tools:ignore="LabelFor"/>
|
||||
|
|
Loading…
Reference in New Issue
Block a user