android - 片段 null 必须是一个公共静态类,才能从运行应用程序的实例状态正确重新创建
问题描述
运行应用程序时出现此错误
片段 null 必须是公共静态类才能从实例状态正确重新创建
关于 newfragment.show 声明。
我在 DatePickerFragment 上得到了 lint,要求是静态的,但是是静态的……有什么建议吗?我已经检查了其他类似的问题,但不帮助我
// picker calendar
birthdate.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
DialogFragment newFragment = new DatePickerFragment() {
@Override
public void onDateSet(DatePicker view, int year, int month, int day) {
String birthdatestr = (day + "/" + (month + 1) + "/" + year);
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy", Locale.US);
Date datebirth = null;
try {
datebirth = formatter.parse(birthdatestr);
} catch (ParseException e) {
e.printStackTrace();
}
DateFormat f =
DateFormat.getDateInstance(DateFormat.LONG, Locale.getDefault());
String formattedDate = f.format(datebirth);
birthdate.setText(formattedDate);
if (datebirth != null) {
birthmills = datebirth.getTime();
}
}
};
newFragment.show(getFragmentManager(), "Date Picker");
}
});
}
public static class DatePickerFragment extends DialogFragment
implements DatePickerDialog.OnDateSetListener {
public String data;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
final Calendar c = getInstance();
int year = c.get(YEAR);
int month = c.get(MONTH);
int day = c.get(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
}
public String getData() {
return data;
}
}
解决方案
推荐阅读
- python - 我无法在 Mac 上使用 Python3 安装 Psycopg2。我已经安装了 Python3 和 pip3
- ios - 使用 Button 生成 FlexBox 布局
- javascript - 测试方法被过度指定
- mule - Define global dataweave function in mule 3
- c - 默认情况下,局部变量中有什么?
- python - Tokenisation with Spacy - how to get left and right tokens
- json - Networking using JSONDecoder & codable protocol
- jquery - 如何创建可搜索的下拉列表
- ios - 120 Hz 的 iOS 设备 - UIKit 刷新率是多少
- c# - 将 Byte 数组转换为不同类型项的集合