title: How to Make DatePicker Only Show Spinner Using Java
body: <p>I'm trying to get a user to select a date by clicking on a button and having a datepicker dialog show up. However, no matter how I change the xml file, the spinner view won't show up, and I'm under the impression that the xml file isn't even being used.</p>
  
  <pre><code>public class Page extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
  
  private Calendar calendar;
  private EditText date;
  private DatePicker datePicker;
  private int year, month, day;
  
  static final int DATE_DIALOG_ID = 1;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_page);
  
      date = (EditText) findViewById(R.id.date);
      datePicker = (DatePicker) findViewById(R.id.datePicker);
      calendar = Calendar.getInstance();
      year = calendar.get(Calendar.YEAR);
  
      month = calendar.get(Calendar.MONTH);
      day = calendar.get(Calendar.DAY_OF_MONTH);
      showDate(year, month + 1, day);
  
      ... [other unrelated code]
  
      Spinner mySpinner = (Spinner) findViewById(R.id.mySpinner);
      mySpinner.setOnItemSelectedListener(this);
  
      ArrayAdapter&lt;CharSequence&gt; adapter = ArrayAdapter.createFromResource(this, R.array.spinnerItems, android.R.layout.simple_spinner_item);
  
      adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      mySpinner.setAdapter(adapter);
  
      ... [other unrelated code]
  
  
  }
  
  @SuppressWarnings("deprecation")
  public void setDate(View view) {
  
      showDialog(1);
  }
  
   @Override
   protected Dialog onCreateDialog(int id) {
   // TODO Auto-generated method stub
   if (id == 1) {
   return new DatePickerDialog(this, myDateListener, year, month, day);
   }
   return null;
   }
  
   private DatePickerDialog.OnDateSetListener myDateListener = new DatePickerDialog.OnDateSetListener() {
   @Override
   public void onDateSet(DatePicker arg0, int arg1, int arg2, int arg3) {
  
   showDate(arg1, arg2+1, arg3);
   }
   };
  
   private void showDate(int year, int month, int day) {
   date.setText(new StringBuilder().append(day).append("/")
   .append(month).append("/").append(year));
   }
  </code></pre>
  
  <p>When the button is clicked, the method setDate is called. I initialized a datepicker earlier in my Java code, but it doesn't seem to be doing anything. Here's the xml for my datepicker:</p>
  
  <pre><code> &lt;DatePicker
      android:id="@+id/datePicker"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:calendarViewShown="false"
      android:datePickerMode="spinner"
      android:layout_centerVertical="true"
      android:layout_centerHorizontal="true"/&gt;
  </code></pre>
  
  <p>Edit: Log after clicking ImageButton
  09-03 10:31:15.719    1895-1910/com.home.Home W/EGL_emulation﹕ eglSurfaceAttrib not implemented
  09-03 10:31:15.720    1895-1910/com.home.Home W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa54a3420, error=EGL_SUCCESS</p>
  
  <p>Edit: XML file</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context="com.home.Home.Home"&gt;
  
   &lt;ImageButton
      android:id="@+id/selectDate"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:src="@drawable/select_date"
      android:text="@string/select_date"
      android:onClick="setDate"/&gt;
  
   &lt;EditText
      android:id="@+id/date"
      android:hint="@string/date_hint"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"/&gt;
  
  &lt;DatePicker
      android:id="@+id/datePicker"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:calendarViewShown="false"
      android:datePickerMode="spinner"
      android:layout_centerVertical="true"
      android:layout_centerHorizontal="true"/&gt;
  </code></pre>
  
  <p></p>
  
  <p>Any help is appreciated!</p>