title: Hide Day, Month, or Year from DatePicker in Android 5.0+ Lollipop
body: <p>I've been searching for a solution to hide any one of the following spinners from the DatePicker.  For Android 5.0 the internal variables were changed and, in my case, the Day and Month spinners were visible again after the update to my device.  </p>
  
  <p><strong>Android 4.4 and Kitkat Solution</strong></p>
  
  <pre><code>DatePicker dpDate = (DatePicker) findViewById(R.id.dpDate);
  
      // Initialize Date Picker
      int year    = dpDate.getYear();
      int month   = dpDate.getMonth();
      int day     = dpDate.getDayOfMonth();
      dpDate.init(year, month, day, this);
  
  Field f[] = dpDate.getClass().getDeclaredFields();
              for (Field field : f) 
              {
                  // Hides the DAY spinner
                  if(field.getName().equals("mDayPicker") || field.getName().equals("mDaySpinner")) 
                  {
                      field.setAccessible(true);
                      Object dayPicker = new Object();
                      dayPicker = field.get(dpDate);
                      ((View) dayPicker).setVisibility(View.GONE);
                  }
  
                  // Hides the MONTH spinner
                  if(field.getName().equals("mMonthPicker") || field.getName().equals("mMonthSpinner")) 
                  {
                      field.setAccessible(true);
                      Object monthPicker = new Object();
                      monthPicker = field.get(dpDate);
                      ((View) monthPicker).setVisibility(View.GONE);
                  }
  
                  // Hides the YEAR spinner
                  if(field.getName().equals("mYearPicker") || field.getName().equals("mYearSpinner")) 
                  {
                      field.setAccessible(true);
                      Object yearPicker = new Object();
                      yearPicker = field.get(dpDate);
                      ((View) myearPicker).setVisibility(View.GONE);
                  }
              }
  </code></pre>
  
  <p><strong>Android 5.0+ Lollipop Solution</strong></p>
  
  <pre><code>    DatePicker dpDate = (DatePicker) findViewById(R.id.dpDate);
  
      // Initialize Date Picker
      int year    = dpDate.getYear();
      int month   = dpDate.getMonth();
      int day     = dpDate.getDayOfMonth();
      dpDate.init(year, month, day, this);
  
      if (android.os.Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.LOLLIPOP) 
              {
                  int daySpinnerId = Resources.getSystem().getIdentifier("day", "id", "android");
                  if (daySpinnerId != 0) 
                  {
                      View daySpinner = dpDate.findViewById(daySpinnerId);
                      if (daySpinner != null) 
                      {
                          daySpinner.setVisibility(View.GONE);
                      }
                  }
              }
  
              if (android.os.Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.LOLLIPOP) 
              {
                  int monthSpinnerId = Resources.getSystem().getIdentifier("month", "id", "android");
                  if (monthSpinnerId != 0) 
                  {
                      View monthSpinner = dpDate.findViewById(monthSpinnerId);
                      if (monthSpinner != null) 
                      {
                          monthSpinner.setVisibility(View.GONE);
                      }
                  }
              }
  
              if (android.os.Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.LOLLIPOP) 
              {
                  int yearSpinnerId = Resources.getSystem().getIdentifier("year", "id", "android");
                  if (yearSpinnerId != 0) 
                  {
                      View yearSpinner = dpDate.findViewById(yearSpinnerId);
                      if (yearSpinner != null) 
                      {
                          yearSpinner.setVisibility(View.GONE);
                      }
                  }
              }
  </code></pre>
  
  <p>I found the above solution to this problem here:
  <a href="https://stackoverflow.com/questions/26460682/custom-date-picker-dialog-in-android-lollipop">Custom Date Picker Dialog in Android Lollipop</a></p>
  
  <p>I wanted to make sure that it was easily searchable so others could benefit from this so I created this new post.  (The solution took me several hours to locate and understand, so I hope to help someone with this).</p>
  
  <p>I've tested this and it works perfectly.  In fact, if you put the solution for the Lollipop first and then under that, in the code, put the solution for Kitkat, then it is compatible for both versions without interference.  (Make sure to use try/catch ;)</p>
  
  <p><strong>EDIT 7.22.2015:</strong>
  I thought it was obvious if one was using a DatePicker that it needed to be initialized.  I included the code to show that you need to initialize the DatePicker before you run the rest of the code (in both situations) otherwise your Views will throw a NullPointerException.  That includes the yearSpinner throwing a null.  Also, you should have at least one view for the date, don't hide all 3, i.e., don't hide the day, month, and the year at the same time.</p>