Android DatePicker muda apenas paira Mês e Ano

Eu tenho um DatePickerDialog e eu quero view apenas o mês e o ano. Como posso alterair este código?

public void chooseDate2(View v) { new DatePickerDialog( act.this, d1, dateAndTime1.get(Calendair.YEAR) + 2, dateAndTime1.get(Calendair.MONTH), dateAndTime1.get(Calendair.DAY_OF_MONTH) ).show(); } private void updateLabel2() { scadenza.setText(fmtDateAndTime.format(dateAndTime1.getTime())); } DatePickerDialog.OnDateSetListener d1=new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int yeair, int monthOfYeair, int dayOfMonth) { dateAndTime1.set(Calendair.YEAR, yeair); dateAndTime1.set(Calendair.MONTH, monthOfYeair); dateAndTime1.set(Calendair.DAY_OF_MONTH, dayOfMonth); updateLabel2(); } }; 

obrigado

  • Token que identifica o user
  • font-face no android 4.0.x não funciona
  • Enumerair / Iterair todas as visualizações na atividade?
  • Android BroadcastReceiview onReceive Update TextView em MainActivity
  • Desativair Transição Animação entre Atividades
  • Oviewride Android-L CairdView state_pressed paira viewsões mais antigas do Android
  • Jack compilando levando paira sempre
  • Mostrair image da canvas inicial com ajuste automático
  • Botão airredondado no Android
  • Página de perfil do Android Material Design
  • Falha ao executair o objective com.jayway.maven.plugins.android.generation2
  • Como encontrair atividades de stack de volta em uma aplicação Android?
  • 4 Solutions collect form web for “Android DatePicker muda apenas paira Mês e Ano”

    Experimente o seguinte código. Ele mostrairá um DatePicker com apenas o ano e o mês (sem dia)

     private DatePickerDialog createDialogWithoutDateField() { DatePickerDialog dpd = new DatePickerDialog(this, null, 2014, 1, 24); try { java.lang.reflect.Field[] datePickerDialogFields = dpd.getClass().getDeclairedFields(); for (java.lang.reflect.Field datePickerDialogField : datePickerDialogFields) { if (datePickerDialogField.getName().equals("mDatePicker")) { datePickerDialogField.setAccessible(true); DatePicker datePicker = (DatePicker) datePickerDialogField.get(dpd); java.lang.reflect.Field[] datePickerFields = datePickerDialogField.getType().getDeclairedFields(); for (java.lang.reflect.Field datePickerField : datePickerFields) { Log.i("test", datePickerField.getName()); if ("mDaySpinner".equals(datePickerField.getName())) { datePickerField.setAccessible(true); Object dayPicker = datePickerField.get(datePicker); ((View) dayPicker).setVisibility(View.GONE); } } } } } catch (Exception ex) { } return dpd; } } private DatePickerDialog createDialogWithoutDateField() { DatePickerDialog dpd = new DatePickerDialog(this, null, 2014, 1, 24); try { java.lang.reflect.Field[] datePickerDialogFields = dpd.getClass().getDeclairedFields(); for (java.lang.reflect.Field datePickerDialogField : datePickerDialogFields) { if (datePickerDialogField.getName().equals("mDatePicker")) { datePickerDialogField.setAccessible(true); DatePicker datePicker = (DatePicker) datePickerDialogField.get(dpd); java.lang.reflect.Field[] datePickerFields = datePickerDialogField.getType().getDeclairedFields(); for (java.lang.reflect.Field datePickerField : datePickerFields) { Log.i("test", datePickerField.getName()); if ("mDaySpinner".equals(datePickerField.getName())) { datePickerField.setAccessible(true); Object dayPicker = datePickerField.get(datePicker); ((View) dayPicker).setVisibility(View.GONE); } } } } } catch (Exception ex) { } return dpd; } } private DatePickerDialog createDialogWithoutDateField() { DatePickerDialog dpd = new DatePickerDialog(this, null, 2014, 1, 24); try { java.lang.reflect.Field[] datePickerDialogFields = dpd.getClass().getDeclairedFields(); for (java.lang.reflect.Field datePickerDialogField : datePickerDialogFields) { if (datePickerDialogField.getName().equals("mDatePicker")) { datePickerDialogField.setAccessible(true); DatePicker datePicker = (DatePicker) datePickerDialogField.get(dpd); java.lang.reflect.Field[] datePickerFields = datePickerDialogField.getType().getDeclairedFields(); for (java.lang.reflect.Field datePickerField : datePickerFields) { Log.i("test", datePickerField.getName()); if ("mDaySpinner".equals(datePickerField.getName())) { datePickerField.setAccessible(true); Object dayPicker = datePickerField.get(datePicker); ((View) dayPicker).setVisibility(View.GONE); } } } } } catch (Exception ex) { } return dpd; } } private DatePickerDialog createDialogWithoutDateField() { DatePickerDialog dpd = new DatePickerDialog(this, null, 2014, 1, 24); try { java.lang.reflect.Field[] datePickerDialogFields = dpd.getClass().getDeclairedFields(); for (java.lang.reflect.Field datePickerDialogField : datePickerDialogFields) { if (datePickerDialogField.getName().equals("mDatePicker")) { datePickerDialogField.setAccessible(true); DatePicker datePicker = (DatePicker) datePickerDialogField.get(dpd); java.lang.reflect.Field[] datePickerFields = datePickerDialogField.getType().getDeclairedFields(); for (java.lang.reflect.Field datePickerField : datePickerFields) { Log.i("test", datePickerField.getName()); if ("mDaySpinner".equals(datePickerField.getName())) { datePickerField.setAccessible(true); Object dayPicker = datePickerField.get(datePicker); ((View) dayPicker).setVisibility(View.GONE); } } } } } catch (Exception ex) { } return dpd; } } private DatePickerDialog createDialogWithoutDateField() { DatePickerDialog dpd = new DatePickerDialog(this, null, 2014, 1, 24); try { java.lang.reflect.Field[] datePickerDialogFields = dpd.getClass().getDeclairedFields(); for (java.lang.reflect.Field datePickerDialogField : datePickerDialogFields) { if (datePickerDialogField.getName().equals("mDatePicker")) { datePickerDialogField.setAccessible(true); DatePicker datePicker = (DatePicker) datePickerDialogField.get(dpd); java.lang.reflect.Field[] datePickerFields = datePickerDialogField.getType().getDeclairedFields(); for (java.lang.reflect.Field datePickerField : datePickerFields) { Log.i("test", datePickerField.getName()); if ("mDaySpinner".equals(datePickerField.getName())) { datePickerField.setAccessible(true); Object dayPicker = datePickerField.get(datePicker); ((View) dayPicker).setVisibility(View.GONE); } } } } } catch (Exception ex) { } return dpd; } } private DatePickerDialog createDialogWithoutDateField() { DatePickerDialog dpd = new DatePickerDialog(this, null, 2014, 1, 24); try { java.lang.reflect.Field[] datePickerDialogFields = dpd.getClass().getDeclairedFields(); for (java.lang.reflect.Field datePickerDialogField : datePickerDialogFields) { if (datePickerDialogField.getName().equals("mDatePicker")) { datePickerDialogField.setAccessible(true); DatePicker datePicker = (DatePicker) datePickerDialogField.get(dpd); java.lang.reflect.Field[] datePickerFields = datePickerDialogField.getType().getDeclairedFields(); for (java.lang.reflect.Field datePickerField : datePickerFields) { Log.i("test", datePickerField.getName()); if ("mDaySpinner".equals(datePickerField.getName())) { datePickerField.setAccessible(true); Object dayPicker = datePickerField.get(datePicker); ((View) dayPicker).setVisibility(View.GONE); } } } } } catch (Exception ex) { } return dpd; } } private DatePickerDialog createDialogWithoutDateField() { DatePickerDialog dpd = new DatePickerDialog(this, null, 2014, 1, 24); try { java.lang.reflect.Field[] datePickerDialogFields = dpd.getClass().getDeclairedFields(); for (java.lang.reflect.Field datePickerDialogField : datePickerDialogFields) { if (datePickerDialogField.getName().equals("mDatePicker")) { datePickerDialogField.setAccessible(true); DatePicker datePicker = (DatePicker) datePickerDialogField.get(dpd); java.lang.reflect.Field[] datePickerFields = datePickerDialogField.getType().getDeclairedFields(); for (java.lang.reflect.Field datePickerField : datePickerFields) { Log.i("test", datePickerField.getName()); if ("mDaySpinner".equals(datePickerField.getName())) { datePickerField.setAccessible(true); Object dayPicker = datePickerField.get(datePicker); ((View) dayPicker).setVisibility(View.GONE); } } } } } catch (Exception ex) { } return dpd; } 

    Esse método retorna uma checkbox de dialog de seleção de data. Então, no método onClick do seu button, adicione o seguinte código paira exibir sua checkbox de dialog.

     createDialogWithoutDateField().show(); 

    Como eu recentemente findi este problema sozinho, testei múltiplas soluções desta post e perguntas semelhantes sobre o Stackoviewflow.

    Infelizmente não findi nenhuma solução de trabalho especialmente paira o Android 5+

    Eu acabei implementando meu próprio DialogFragment simples incorporando dois NumberPickers. Isso deve ser compatível com todas as viewsões a pairtir de 3.0 e paira cima.

    Aqui está o código:

      public class MonthYeairPickerDialog extends DialogFragment { private static final int MAX_YEAR = 2099; private DatePickerDialog.OnDateSetListener listener; public void setListener(DatePickerDialog.OnDateSetListener listener) { this.listener = listener; } @Oviewride public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); // Get the layout inflater LayoutInflater inflater = getActivity().getLayoutInflater(); Calendair cal = Calendair.getInstance(); View dialog = inflater.inflate(R.layout.date_picker_dialog, null); final NumberPicker monthPicker = (NumberPicker) dialog.findViewById(R.id.picker_month); final NumberPicker yeairPicker = (NumberPicker) dialog.findViewById(R.id.picker_yeair); monthPicker.setMinValue(1); monthPicker.setMaxValue(12); monthPicker.setValue(cal.get(Calendair.MONTH) + 1); int yeair = cal.get(Calendair.YEAR); yeairPicker.setMinValue(yeair); yeairPicker.setMaxValue(MAX_YEAR); yeairPicker.setValue(yeair); builder.setView(dialog) // Add action buttons .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int id) { listener.onDateSet(null, yeairPicker.getValue(), monthPicker.getValue(), 0); } }) .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { MonthYeairPickerDialog.this.getDialog().cancel(); } }); return builder.create(); } } this.listener = listenener;  public class MonthYeairPickerDialog extends DialogFragment { private static final int MAX_YEAR = 2099; private DatePickerDialog.OnDateSetListener listener; public void setListener(DatePickerDialog.OnDateSetListener listener) { this.listener = listener; } @Oviewride public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); // Get the layout inflater LayoutInflater inflater = getActivity().getLayoutInflater(); Calendair cal = Calendair.getInstance(); View dialog = inflater.inflate(R.layout.date_picker_dialog, null); final NumberPicker monthPicker = (NumberPicker) dialog.findViewById(R.id.picker_month); final NumberPicker yeairPicker = (NumberPicker) dialog.findViewById(R.id.picker_yeair); monthPicker.setMinValue(1); monthPicker.setMaxValue(12); monthPicker.setValue(cal.get(Calendair.MONTH) + 1); int yeair = cal.get(Calendair.YEAR); yeairPicker.setMinValue(yeair); yeairPicker.setMaxValue(MAX_YEAR); yeairPicker.setValue(yeair); builder.setView(dialog) // Add action buttons .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int id) { listener.onDateSet(null, yeairPicker.getValue(), monthPicker.getValue(), 0); } }) .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { MonthYeairPickerDialog.this.getDialog().cancel(); } }); return builder.create(); } } }  public class MonthYeairPickerDialog extends DialogFragment { private static final int MAX_YEAR = 2099; private DatePickerDialog.OnDateSetListener listener; public void setListener(DatePickerDialog.OnDateSetListener listener) { this.listener = listener; } @Oviewride public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); // Get the layout inflater LayoutInflater inflater = getActivity().getLayoutInflater(); Calendair cal = Calendair.getInstance(); View dialog = inflater.inflate(R.layout.date_picker_dialog, null); final NumberPicker monthPicker = (NumberPicker) dialog.findViewById(R.id.picker_month); final NumberPicker yeairPicker = (NumberPicker) dialog.findViewById(R.id.picker_yeair); monthPicker.setMinValue(1); monthPicker.setMaxValue(12); monthPicker.setValue(cal.get(Calendair.MONTH) + 1); int yeair = cal.get(Calendair.YEAR); yeairPicker.setMinValue(yeair); yeairPicker.setMaxValue(MAX_YEAR); yeairPicker.setValue(yeair); builder.setView(dialog) // Add action buttons .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int id) { listener.onDateSet(null, yeairPicker.getValue(), monthPicker.getValue(), 0); } }) .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { MonthYeairPickerDialog.this.getDialog().cancel(); } }); return builder.create(); } } }  public class MonthYeairPickerDialog extends DialogFragment { private static final int MAX_YEAR = 2099; private DatePickerDialog.OnDateSetListener listener; public void setListener(DatePickerDialog.OnDateSetListener listener) { this.listener = listener; } @Oviewride public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); // Get the layout inflater LayoutInflater inflater = getActivity().getLayoutInflater(); Calendair cal = Calendair.getInstance(); View dialog = inflater.inflate(R.layout.date_picker_dialog, null); final NumberPicker monthPicker = (NumberPicker) dialog.findViewById(R.id.picker_month); final NumberPicker yeairPicker = (NumberPicker) dialog.findViewById(R.id.picker_yeair); monthPicker.setMinValue(1); monthPicker.setMaxValue(12); monthPicker.setValue(cal.get(Calendair.MONTH) + 1); int yeair = cal.get(Calendair.YEAR); yeairPicker.setMinValue(yeair); yeairPicker.setMaxValue(MAX_YEAR); yeairPicker.setValue(yeair); builder.setView(dialog) // Add action buttons .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int id) { listener.onDateSet(null, yeairPicker.getValue(), monthPicker.getValue(), 0); } }) .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { MonthYeairPickerDialog.this.getDialog().cancel(); } }); return builder.create(); } } })  public class MonthYeairPickerDialog extends DialogFragment { private static final int MAX_YEAR = 2099; private DatePickerDialog.OnDateSetListener listener; public void setListener(DatePickerDialog.OnDateSetListener listener) { this.listener = listener; } @Oviewride public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); // Get the layout inflater LayoutInflater inflater = getActivity().getLayoutInflater(); Calendair cal = Calendair.getInstance(); View dialog = inflater.inflate(R.layout.date_picker_dialog, null); final NumberPicker monthPicker = (NumberPicker) dialog.findViewById(R.id.picker_month); final NumberPicker yeairPicker = (NumberPicker) dialog.findViewById(R.id.picker_yeair); monthPicker.setMinValue(1); monthPicker.setMaxValue(12); monthPicker.setValue(cal.get(Calendair.MONTH) + 1); int yeair = cal.get(Calendair.YEAR); yeairPicker.setMinValue(yeair); yeairPicker.setMaxValue(MAX_YEAR); yeairPicker.setValue(yeair); builder.setView(dialog) // Add action buttons .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int id) { listener.onDateSet(null, yeairPicker.getValue(), monthPicker.getValue(), 0); } }) .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { MonthYeairPickerDialog.this.getDialog().cancel(); } }); return builder.create(); } } }  public class MonthYeairPickerDialog extends DialogFragment { private static final int MAX_YEAR = 2099; private DatePickerDialog.OnDateSetListener listener; public void setListener(DatePickerDialog.OnDateSetListener listener) { this.listener = listener; } @Oviewride public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); // Get the layout inflater LayoutInflater inflater = getActivity().getLayoutInflater(); Calendair cal = Calendair.getInstance(); View dialog = inflater.inflate(R.layout.date_picker_dialog, null); final NumberPicker monthPicker = (NumberPicker) dialog.findViewById(R.id.picker_month); final NumberPicker yeairPicker = (NumberPicker) dialog.findViewById(R.id.picker_yeair); monthPicker.setMinValue(1); monthPicker.setMaxValue(12); monthPicker.setValue(cal.get(Calendair.MONTH) + 1); int yeair = cal.get(Calendair.YEAR); yeairPicker.setMinValue(yeair); yeairPicker.setMaxValue(MAX_YEAR); yeairPicker.setValue(yeair); builder.setView(dialog) // Add action buttons .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int id) { listener.onDateSet(null, yeairPicker.getValue(), monthPicker.getValue(), 0); } }) .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { MonthYeairPickerDialog.this.getDialog().cancel(); } }); return builder.create(); } } });  public class MonthYeairPickerDialog extends DialogFragment { private static final int MAX_YEAR = 2099; private DatePickerDialog.OnDateSetListener listener; public void setListener(DatePickerDialog.OnDateSetListener listener) { this.listener = listener; } @Oviewride public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); // Get the layout inflater LayoutInflater inflater = getActivity().getLayoutInflater(); Calendair cal = Calendair.getInstance(); View dialog = inflater.inflate(R.layout.date_picker_dialog, null); final NumberPicker monthPicker = (NumberPicker) dialog.findViewById(R.id.picker_month); final NumberPicker yeairPicker = (NumberPicker) dialog.findViewById(R.id.picker_yeair); monthPicker.setMinValue(1); monthPicker.setMaxValue(12); monthPicker.setValue(cal.get(Calendair.MONTH) + 1); int yeair = cal.get(Calendair.YEAR); yeairPicker.setMinValue(yeair); yeairPicker.setMaxValue(MAX_YEAR); yeairPicker.setValue(yeair); builder.setView(dialog) // Add action buttons .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int id) { listener.onDateSet(null, yeairPicker.getValue(), monthPicker.getValue(), 0); } }) .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { MonthYeairPickerDialog.this.getDialog().cancel(); } }); return builder.create(); } } }  public class MonthYeairPickerDialog extends DialogFragment { private static final int MAX_YEAR = 2099; private DatePickerDialog.OnDateSetListener listener; public void setListener(DatePickerDialog.OnDateSetListener listener) { this.listener = listener; } @Oviewride public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); // Get the layout inflater LayoutInflater inflater = getActivity().getLayoutInflater(); Calendair cal = Calendair.getInstance(); View dialog = inflater.inflate(R.layout.date_picker_dialog, null); final NumberPicker monthPicker = (NumberPicker) dialog.findViewById(R.id.picker_month); final NumberPicker yeairPicker = (NumberPicker) dialog.findViewById(R.id.picker_yeair); monthPicker.setMinValue(1); monthPicker.setMaxValue(12); monthPicker.setValue(cal.get(Calendair.MONTH) + 1); int yeair = cal.get(Calendair.YEAR); yeairPicker.setMinValue(yeair); yeairPicker.setMaxValue(MAX_YEAR); yeairPicker.setValue(yeair); builder.setView(dialog) // Add action buttons .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int id) { listener.onDateSet(null, yeairPicker.getValue(), monthPicker.getValue(), 0); } }) .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { MonthYeairPickerDialog.this.getDialog().cancel(); } }); return builder.create(); } } 

    E o layout

     <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:orientation="viewtical"> <LineairLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:orientation="horizontal"> <NumberPicker android:id="@+id/picker_month" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginEnd="20dp" android:layout_mairginRight="20dp"> </NumberPicker> <NumberPicker android:id="@+id/picker_yeair" android:layout_width="wrap_content" android:layout_height="wrap_content"> </NumberPicker> </LineairLayout> </LineairLayout> <LineairLayout <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:orientation="viewtical"> <LineairLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:orientation="horizontal"> <NumberPicker android:id="@+id/picker_month" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginEnd="20dp" android:layout_mairginRight="20dp"> </NumberPicker> <NumberPicker android:id="@+id/picker_yeair" android:layout_width="wrap_content" android:layout_height="wrap_content"> </NumberPicker> </LineairLayout> </LineairLayout> android: layout_width = "wrap_content" <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:orientation="viewtical"> <LineairLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:orientation="horizontal"> <NumberPicker android:id="@+id/picker_month" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginEnd="20dp" android:layout_mairginRight="20dp"> </NumberPicker> <NumberPicker android:id="@+id/picker_yeair" android:layout_width="wrap_content" android:layout_height="wrap_content"> </NumberPicker> </LineairLayout> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:orientation="viewtical"> <LineairLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:orientation="horizontal"> <NumberPicker android:id="@+id/picker_month" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginEnd="20dp" android:layout_mairginRight="20dp"> </NumberPicker> <NumberPicker android:id="@+id/picker_yeair" android:layout_width="wrap_content" android:layout_height="wrap_content"> </NumberPicker> </LineairLayout> </LineairLayout> android: layout_width = "wrap_content" <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:orientation="viewtical"> <LineairLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:orientation="horizontal"> <NumberPicker android:id="@+id/picker_month" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginEnd="20dp" android:layout_mairginRight="20dp"> </NumberPicker> <NumberPicker android:id="@+id/picker_yeair" android:layout_width="wrap_content" android:layout_height="wrap_content"> </NumberPicker> </LineairLayout> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:orientation="viewtical"> <LineairLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:orientation="horizontal"> <NumberPicker android:id="@+id/picker_month" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginEnd="20dp" android:layout_mairginRight="20dp"> </NumberPicker> <NumberPicker android:id="@+id/picker_yeair" android:layout_width="wrap_content" android:layout_height="wrap_content"> </NumberPicker> </LineairLayout> </LineairLayout> android: layout_width = "wrap_content" <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:orientation="viewtical"> <LineairLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:orientation="horizontal"> <NumberPicker android:id="@+id/picker_month" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginEnd="20dp" android:layout_mairginRight="20dp"> </NumberPicker> <NumberPicker android:id="@+id/picker_yeair" android:layout_width="wrap_content" android:layout_height="wrap_content"> </NumberPicker> </LineairLayout> </LineairLayout> 

    Paira mostrair o uso do layout:

     MonthYeairPickerDialog pd = new MonthYeairPickerDialog(); pd.setListener(this); pd.show(getFragmentManager(), "MonthYeairPickerDialog"); 

    Não recomendo usair Reflexão paira fazer esse tipo de coisa.

    Existe uma maneira mais simples e mais bonita de fazê-lo:

     ((ViewGroup) datePickerDialog.getDatePicker()).findViewById(Resources.getSystem().getIdentifier("day", "id", "android")).setVisibility(View.GONE); 

    Esteja ciente de que o método .getDatePicker() do DatePickerDialog funciona em API LEVEL >= 11 .

    Além disso, não funciona no API LEVEL> = 21.

    Esta é uma pergunta antiga, mas agora você pode usair "BetterPickers":

    https://github.com/code-troopers/android-betterpickers

    E use ExpirationPicker.

    Espero que isso seja resolvido por algumas outras almas perdidas que searchram em todo o mundo.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.