in my project there DialogFragment
.
public class MyDatePicer extends DialogFragment implements DatePickerDialog.OnDateSetListener {
private TextView tv;
public MyDatePicer(TextView tv) {
this.tv = tv;
}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
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);
Dialog picker = new DatePickerDialog(getActivity(), this, year, month, day);
picker.setTitle("Выбереите дату");
return picker;
}
@Override
public void onStart() {
super.onStart();
Button nButton = ((AlertDialog) getDialog())
.getButton(DialogInterface.BUTTON_POSITIVE);
nButton.setText("Готово");
}
@Override
public void onDateSet(android.widget.DatePicker datePicker, int year,int month, int day) {
tv.setText(day + "-" + (month + 1) + "-" + year);
}
}
and in my passage I call it:
dateBegin = (TextView) v.findViewById(R.id.dateBegin);
dateEnd = (TextView) v.findViewById(R.id.dateEnd);
....
case R.id.dateBegin:
dateDialog = new MyDatePicer(dateBegin);
dateDialog.show(getActivity().getSupportFragmentManager(), "datePicker");
break;
case R.id.dateEnd:
dateDialog = new MyDatePicer(dateEnd);
dateDialog.show(getActivity().getSupportFragmentManager(), "datePicker");
break;
everything works as I need to. I run on the emulator and on my phone and it works. but when I try to build an android APK studio produces an error:
Error:Error: This fragment should provide a default constructor (a public constructor with no arguments) (com.managment.pavel.managmentgradle.fragments.MyDatePicer) [ValidFragment]
I do not know how else to convey View(TextView my date) in another class. I do not know how to build APK so that I have. tell me what do I fix?