0

I get this error running the app

Fragment null must be a public static class to be properly recreated from instance state

on newfragment.show statment.

i got lint on DatePickerFragment asking to be static, but is static...any advise? I already check other similar question but do not help me

// 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;
    }
}
Vulneraria
  • 139
  • 1
  • 9

0 Answers0