gpt4 book ai didi

java - 如何获取另一个fragment中EditText中TimePickerDialog的时间?

转载 作者:行者123 更新时间:2023-12-01 18:07:51 24 4
gpt4 key购买 nike

我正在尝试将 TimePickerDialog 的时间获取到 FinishPostFragment 中的 EditText

我现在在 Toast 中显示所选时间,但如何在 FinishPostFragmentEditText 中显示数据?

我的 onCreateView 中的 FinishPostFragment:

timeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// view TimePickerDialog
showTimeDialog(v);
}
});

在我的 onCreateView 之外完成 FinishPostFragment:

public void showTimeDialog(View v){
TimeDialogFragment tdf = new TimeDialogFragment();
tdf.show(getFragmentManager().beginTransaction(), "TimePickerFragment");
}

TimePickerDialog.OnTimeSetListener test = new TimePickerDialog.OnTimeSetListener(){
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
time_finish.setText(String.valueOf(hourOfDay) + ":" + String.valueOf(minute));
}
};

时间设置.java:

public class TimeSettings implements TimePickerDialog.OnTimeSetListener {
Context context;

public TimeSettings(Context context){
this.context = context;
}

@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
Toast.makeText(context, "Selected time is hour: " +hourOfDay+ " minute: " + minute, Toast.LENGTH_LONG).show();
}
}

时间对话框 fragment :

public class TimeDialogFragment extends DialogFragment {

@Override
public Dialog onCreateDialog(Bundle savedInstanceState){
Calendar calendar = Calendar.getInstance();

int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);

TimePickerDialog dialog;

TimeSettings timeSettings = new TimeSettings(getActivity());
dialog = new TimePickerDialog(getActivity(), timeSettings, hour, minute,
android.text.format.DateFormat.is24HourFormat(getActivity()));

return dialog;
}
}

最佳答案

@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {

Toast.makeText(context, "Selected time is hour: " +hourOfDay+ " minute: " + minute, Toast.LENGTH_LONG).show();
String time = " "+hourString+"h"+minuteString+"m"+secondString+"s";
yourTextView.setText(time);

}

尝试像这样将文本设置到您的 TextView 。

关于java - 如何获取另一个fragment中EditText中TimePickerDialog的时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34912360/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com