0

I have a DatePicker as follows:

 <DatePicker
  android:id="@+id/dpMyDatePicker"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_gravity="center"
  android:calendarViewShown="false"
  android:datePickerMode="spinner"/>

Is there a way that does not show the days? (only month and year)

If it is by programming, is there a simple example of how to do it?

Thanks.

Fabián Romo
  • 319
  • 2
  • 14

1 Answers1

0

@RequiresApi(api = Build.VERSION_CODES.N)
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_detalles_tarjeta);

        dpMyaDatePicker = findViewById(R.id.dpMyaDatePicker);
        dpMyaDatePicker.init(
                Calendar.getInstance().get(Calendar.YEAR),
                Calendar.getInstance().get(Calendar.MONTH),
                Calendar.getInstance().get(Calendar.DAY_OF_MONTH),



                new DatePicker.OnDateChangedListener(){
                    @Override
                    public void onDateChanged(DatePicker view,int year, int monthOfYear,int dayOfMonth) {

                    }
                });
        int daySpinnerId = Resources.getSystem().getIdentifier("day", "id", "android");
        if (daySpinnerId != 0)
        {
            View daySpinner = dpMyaDatePicker.findViewById(daySpinnerId);
            if (daySpinner != null)
            {
                daySpinner.setVisibility(View.INVISIBLE);
            }
        }
    }
Fabián Romo
  • 319
  • 2
  • 14