Calendar View not showing in android DatePicker

40 views Asked by At

I have added android.app.DatePickerDialog for selecting date from the user. The dialog was working properly on most of the mobile devices. But in Samsung mobiles calendar view is not showing, only blank screen was showing.

enter image description here

1

There are 1 answers

0
Muhammad Asad On
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.widget.DatePicker;

import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment;

import java.util.Calendar;

public class DatePickerFragment extends DialogFragment implements 
DatePickerDialog.OnDateSetListener {

@NonNull
@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);
}

@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
    // Handle the selected date
}
}

calling this calling like this :

DatePickerFragment datePickerFragment = new DatePickerFragment();
datePickerFragment.show(getSupportFragmentManager(), "datePicker");