【发布时间】:2019-05-29 17:42:39
【问题描述】:
当您选择日、月和年时,请始终保存今天的时间。这是我尝试过的
private DatePicker.OnDateChangedListener dateSetListener = new DatePicker.OnDateChangedListener() {
public void onDateChanged(DatePicker view, int año, int mes,
int dia) {
isDateChanged = true;
}
};
private void AgregarCumpleaños() {
if (isDateChanged = false)
{
Toast.makeText(this, "Elija su cumpleaños", Toast.LENGTH_SHORT).show();
}
else
{
datePicker = findViewById(R.id.cumpleano);
final Calendar ca = Calendar.getInstance();
int dia = ca.get(Calendar.DAY_OF_MONTH);
int mes = ca.get(Calendar.MONTH);
int año = ca.get(Calendar.YEAR);
final SimpleDateFormat dateFormatter = new SimpleDateFormat("dd-MMM");
saveCurrentDate = dateFormatter.format(ca.getTime());
我需要保存选定的月份和日期或将其保存在其变量中
【问题讨论】:
-
我认为你只需要更仔细地研究几个类似的例子,并学习正确的方法。您也可以考虑扔掉早已过时且设计不佳的
Calendar类和朋友,并将ThreeTenABP 添加到您的Android 项目中,以便使用java.time,现代Java 日期和时间API。使用起来感觉好多了。
标签: android datepicker calendar