private int year;
private int monthOfYear;
private int dayOfMonth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button);
Calendar calendar = Calendar.getInstance();
year = calendar.get(Calendar.YEAR);
monthOfYear = calendar.get(Calendar.MONTH);
dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
DatePickerDialog pickerDialog = new DatePickerDialog(MainActivity.this, new OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this, year + "年" + monthOfYear + "月" + dayOfMonth + "日", 1).show();
}
}, year, monthOfYear, dayOfMonth);
pickerDialog.show();
}
});
}