gpt4 book ai didi

java - Android 注释 DialogFragment

转载 作者:行者123 更新时间:2023-12-01 12:41:46 27 4
gpt4 key购买 nike

我正在尝试使用 android 注释创建 DialogFragment。

我已经创建了dialogFragment类wint fragment 注释,但不知道下一步是什么:

@EFragment
public class DatePickerFragment extends DialogFragment
implements DatePickerDialog.OnDateSetListener {

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);

// Create a new instance of DatePickerDialog and return it
return new DatePickerDialog(getActivity(), this, year, month, day);
}

public Date Value;

public void onDateSet(DatePicker view, int year, int month, int day) {
Calendar c = Calendar.getInstance();
c.set(year,month,day);
Value = c.getTime();
}
}

你能告诉我如何使用这个类并调用fragment。另外,我想在对话框关闭后获取值。

最佳答案

按照 WonderCsabo 的建议,您应该创建对话 fragment ,然后您应该使用 FragmentTransaction 来显示它。

下面是一个例子:

// create a FragmentTransaction from the FragmentManager
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.addToBackStack(null);

// Create and show the dialog.
DatePickerFragment dFrag = DatePickerFragment_.builder().build();
dFrag.show(ft, "dialog");

关于java - Android 注释 DialogFragment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25039229/

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