<DatePicker
android:id="@+id/dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:calendarViewShown="false"
android:datePickerMode="spinner"
/>
final DatePicker datePicker = findViewById(R.id.dp);
datePicker.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String desc = String.format("你选择的日期是%d年%d月%d日",datePicker.getYear(),datePicker.getMonth() + 1,datePicker.getDayOfMonth());
TextView viewById = findViewById(R.id.tv_date);
viewById.setText(desc);
}
});
标签:datePicker,显示,String,对话框,findViewById,日期,viewById,id
From: https://www.cnblogs.com/loulan/p/16975788.html