I have an android activity in which clicking on an EditText dialog will bring up a date picker. But when I set the date, it is shown incorrectly on the edit text.

This is an example of what I'm talking about: 

* <http://i.imgur.com/7MqO49i.png>
* <http://i.imgur.com/B7lRfnn.png>

Here is the code I used:

```
public class CreateTermWindow extends Activity {

EditText tname, tstart, tend;
Button tcreate;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd", Locale.CANADA);
Calendar calendar1 = Calendar.getInstance();
Calendar calendar2 = Calendar.getInstance();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_create_term_window);

    tname = (EditText) findViewById(R.id.et_newTerm_name);
    tstart = (EditText) findViewById(R.id.et_newTerm_start);
    tend = (EditText) findViewById(R.id.et_newTerm_end);
    tcreate = (Button) findViewById(R.id.btn_newTerm_create);

    tstart.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            new DatePickerDialog(CreateTermWindow.this, c1, calendar1
                    .get(Calendar.YEAR), calendar1.get(Calendar.MONTH),
                    calendar1.get(Calendar.DATE)).show();
        }
    });

    tend.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            new DatePickerDialog(CreateTermWindow.this, c2, calendar2
                    .get(Calendar.YEAR), calendar2.get(Calendar.MONTH),
                    calendar2.get(Calendar.DATE)).show();
        }
    });

    tcreate.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            SQLiteDatabase db = new DatabaseHelper(getBaseContext())
                    .getWritableDatabase();
            ContentValues values = new ContentValues();
            values.put("name", tname.getText().toString());
            values.put("start", tstart.getText().toString());
            values.put("end", tend.getText().toString());
            db.insert("termTable", null, values);
            Toast.makeText(getApplicationContext(), "New Term Created!",
                    Toast.LENGTH_LONG).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.create_term_window, 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();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

private void updateLabel(EditText e, Calendar c) {
    e.setText(sdf.format(c.getTime()));
}

DatePickerDialog.OnDateSetListener c2 = new DatePickerDialog.OnDateSetListener() {
    @Override
    public void onDateSet(DatePicker view, int year, int monthOfYear,
            int dayOfMonth) {
        calendar2.set(Calendar.YEAR, year);
        calendar2.set(Calendar.MONTH, monthOfYear);
        calendar2.set(Calendar.DAY_OF_MONTH, dayOfMonth);
        updateLabel(tend, calendar2);
    }
};

DatePickerDialog.OnDateSetListener c1 = new DatePickerDialog.OnDateSetListener() {
    @Override
    public void onDateSet(DatePicker view, int year, int monthOfYear,
            int dayOfMonth) {
        calendar1.set(Calendar.YEAR, year);
        calendar1.set(Calendar.MONTH, monthOfYear);
        calendar1.set(Calendar.DAY_OF_MONTH, dayOfMonth);
        updateLabel(tstart, calendar1);
    }
};
}

```