日期选择器

public class ChooseADate extends AppCompatActivity {

private Button btnChooseDate;

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

    btnChooseDate = (Button)findViewById(R.id.btnChooseDate);
    btnChooseDate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new DatePickerDialog(ChooseADate.this, new DatePickerDialog.OnDateSetListener() {
                @Override
                public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {

                    String date = String.format("%d-%d-%d",year,month+1,dayOfMonth);
                    System.out.println(String.format("%d-%d-%d",year,month+1,dayOfMonth));
                    btnChooseDate.setText(date);
                }
            },2015,2,30).show();
        }
    });
}

}

你可能感兴趣的:(日期选择器)