title: Android: ListView position and DatePicker
body: <p>I have <strong>onItemClickListener</strong> for the <strong>ListView</strong> that opens <strong>DatePicker</strong> dialog when an item is clicked:</p>
  
  <pre><code>list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
      @Override
      public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
          showDatePickerDialog(view);
      }
  });
  
  public void showDatePickerDialog(View v) {
      DialogFragment newFragment = new DatePickerFragment();
      newFragment.show(getFragmentManager(), "datePicker");
  }
  </code></pre>
  
  <p>After date in DatePicker gets set, I have <strong>onDateSet</strong> method which I want to use to update database and set date for item that was clicked in ListView:</p>
  
  <pre><code>public void onDateSet(DatePicker view, int year, int month, int day) {
      ...
      dataSource.updateDate(adapter.getItemId(position), month + "/" + day + "/" + year);
      ...
  } 
  </code></pre>
  
  <p>How can I pass <strong>ListView position</strong> of the item that was clicked to <strong>onDateSet</strong> so that my database helper knows which record to update?</p>
  
  <hr>
  
  <p><strong>EDIT:</strong> Here's the <strong>DatePickerFragment</strong> class:</p>
  
  <pre><code>public static class DatePickerFragment extends DialogFragment
          implements DatePickerDialog.OnDateSetListener {
  
      @Override
      public Dialog onCreateDialog(Bundle savedInstanceState) {
          // Use the current date as the default date in the picker
          final Calendar c = Calendar.getInstance();
          int year = c.get(Calendar.YEAR);
          int month = c.get(Calendar.MONTH);
          int day = c.get(Calendar.DAY_OF_MONTH);
  
          // Create a new instance of DatePickerDialog and return it
          return new DatePickerDialog(getActivity(), this, year, month, day);
      }
  
      public void onDateSet(DatePicker view, int year, int month, int day) {
          ...
          dataSource.updateDate(adapter.getItemId(position), month + "/" + day + "/" + year);
          ...
      }
  }
  </code></pre>
  
  <p>Thanks!</p>