gpt4 book ai didi

java - 为日期选择器扩展 DialogFragment

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

我正在尝试遵循本教程:http://developer.android.com/guide/topics/ui/controls/pickers.html#DatePicker

这是他们提供的代码,所以我创建了一个新类。但我在新类(class)中遇到了错误。我在定义 public static class DatePickerFragment 时遇到错误。错误是Illegal modifier for the class DatePickerFragment; only public, abstract & final are permitted

public static 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 void onDateSet(DatePicker view, int year, int month, int day) {
// Do something with the date chosen by the user
}
}

最佳答案

我猜您的代码位于单独的 .java 文件中。摆脱static关键字。

如果它是内部类,那么您可以在 Activity 类中使​​用 static 修饰符。

还要检查这个,它表示顶级类不能是静态的

Illegal modifier error for static class

您可以找到一个示例@

How to transfer the formatted date string from my DatePickerFragment?

关于java - 为日期选择器扩展 DialogFragment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22752564/

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