title: Advice with DatePicker code structure Android Studio
body: <p>So I'm very new to android programming, and have no real experience with software building however I do have a basic background with PHP so I get some of the theory behind it all.</p>
  
  <p>I'm currently making a basic Form activity that will store the entries into a DB, which can be recalled in another activity where it can be viewed and edited etc etc.</p>
  
  <p>I have found lots of helpful advice to get to where I am but currently having trouble with how I need to structure the code to implement the DatePicker dialog, the problem I'm facing is the example code for the date picker has</p>
  
  <pre><code>public class MainActivity extends Activity implements OnClickListener {
  </code></pre>
  
  <p>Where as the code in my project is <code>public class New extends ActionBarActivity {</code></p>
  
  <p>So when I edit the line to "implements OnClickListener" my spinner drop downs don't like it.</p>
  
  <p>I have tried entering the code in without the "implements OnClickListener"</p>
  
  <p>Please take a look at what I have and point me in the right direction, I need to understand where its going wrong and how it should be structured.</p>
  
  <pre><code>public class New extends ActionBarActivity {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_new);
  </code></pre>
  
  <p>//Product List</p>
  
  <pre><code>Spinner productList = (Spinner) findViewById(R.id.product);
  
  String[] products = new String[] { "1", "2", "3" };
  
  ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this,
          android.R.layout.simple_spinner_item, products);
  
      productList.setAdapter(adapter);
  
      productList.setOnItemSelectedListener(new OnItemSelectedListener() {
  
          @Override
          public void onItemSelected(AdapterView&lt;?&gt; parent, View view,
                                     int position, long id) {
              Log.v("products", (String) parent.getItemAtPosition(position));
          }
  
          @Override
          public void onNothingSelected(AdapterView&lt;?&gt; parent) {
              // TODO Auto-generated method stub
          }
      });
  </code></pre>
  
  <p>//Reason List</p>
  
  <pre><code>Spinner reasonList = (Spinner) findViewById(R.id.reason);
  
  String[] reasons = new String[] { "A", "B", "C" };
  
  ArrayAdapter&lt;String&gt; adapters = new ArrayAdapter&lt;String&gt;(this,
          android.R.layout.simple_spinner_item, reasons);
  
  reasonList.setAdapter(adapters);
  
  reasonList.setOnItemSelectedListener(new OnItemSelectedListener() {
  
      @Override
      public void onItemSelected(AdapterView&lt;?&gt; parent, View view,
                                 int position, long id) {
          Log.v("reasons", (String) parent.getItemAtPosition(position));
      }
  
      @Override
      public void onNothingSelected(AdapterView&lt;?&gt; parent) {
          // TODO Auto-generated method stub
      }
  });
  </code></pre>
  
  <p>//Start Date Picker</p>
  
  <pre><code>    private EditText StartDate;
  
      private DatePickerDialog StartdatePickerDialog;
  
      private SimpleDateFormat dateFormatter;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_new);
  
          dateFormatter = new SimpleDateFormat("dd-MM-yyyy", Locale.US);
  
          findViewsById();
  
          setDateTimeField();
      }
  
  private void findViewsById() {
  
      StartDate = (EditText) findViewById(R.id.startdate);
      StartDate.setInputType(InputType.TYPE_NULL);
      StartDate.requestFocus();
  
  }
  
  private void setDateTimeField() {
      StartDate.setOnClickListener(this);
  
      Calendar newCalendar = Calendar.getInstance();
      StartdatePickerDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
  
          public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
              Calendar newDate = Calendar.getInstance();
              newDate.set(year, monthOfYear, dayOfMonth);
              StartDate.setText(dateFormatter.format(newDate.getTime()));
          }
  
      }, newCalendar.get(Calendar.YEAR), newCalendar.get(Calendar.MONTH), newCalendar.get(Calendar.DAY_OF_MONTH));
  
  }
  
  
  @Override
  public void onClick(View view) {
      if(view == StartDate) {
          StartDatePickerDialog.show();
      }
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.menu_new, menu);
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      // Handle action bar item clicks here. The action bar will
      // automatically handle clicks on the Home/Up button, so long
      // as you specify a parent activity in AndroidManifest.xml.
      int id = item.getItemId();
  
      //noinspection SimplifiableIfStatement
      if (id == R.id.action_settings) {
          return true;
      }
  
      return super.onOptionsItemSelected(item);
  }
  </code></pre>
  
  <p>}</p>