这些就是核心代码了
final EditText text = (EditText) findViewById(R.id.edit);
final Calendar c = Calendar.getInstance();
text.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
DatePickerDialog dialog = new DatePickerDialog(MainActivity.this, new OnDateSetListener()
{
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth)
{
Calendar c = Calendar.getInstance();
c.set(year, monthOfYear, dayOfMonth);
text.setText(DateFormat.format("yyy-MM-dd", c));
}
}, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH));
dialog.show();
}
});