Can someone assist me in updating an EditText with the selected date from a DatePicker as it changes? Here is my code:
private View view;
private Button next;
private EditText birthday;
private DatePicker datePicker;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_birthday, container, false);
initWidgets();
int day = datePicker.getDayOfMonth();
int month = datePicker.getMonth();
int year = datePicker.getYear();
birthday.setText(day + "/" + month + "/" + year);
return view;
}
private void initWidgets() {
next = view.findViewById(R.id.bt5);
birthday = view.findViewById(R.id.kz5);
datePicker = view.findViewById(R.id.date_picker);
}
This is the XML code for the DatePicker:
<DatePicker
android:id="@+id/date_picker"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:datePickerMode="spinner"
android:layout_marginBottom="40dp"
android:layout_alignParentBottom="true"
android:calendarViewShown="false"/>