gpt4 book ai didi

android - 在 Android 中创建模态日期选择器对话框

转载 作者:行者123 更新时间:2023-11-30 01:42:03 25 4
gpt4 key购买 nike

我有这段代码可以正常工作,但窗口不是模态的,所以更改后我无法获取日期。请给我一些建议或方法,在此先感谢。

代码如下:

final Calendar c = Calendar.getInstance();
int mYear = c.get(Calendar.YEAR);
int mMonth = c.get(Calendar.MONTH);
int mDay = c.get(Calendar.DAY_OF_MONTH);

DatePickerDialog dpd = new DatePickerDialog(this,
new DatePickerDialog.OnDateSetListener() {

public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {

TextView txtDate = null;
txtDate.setText(dayOfMonth + "-" + (monthOfYear + 1) + "-" + year);

}

public void onDateSet1(DatePicker view, int year,
int monthOfYear, int dayOfMonth) { // TODO
// Auto-generated
// method stub

}
}, mYear, mMonth, mDay);

dpd.show();

message("message", "Mensaje", mYear + "/" + mMonth + "/" + mDay, this, context);

最佳答案

private int storeYear = 0;
private int storeMonth = 0;
private int storeDay = 0;

private void function openPicker(){
final TextView txtDate = findViewById(R.id.yourid);
final Calendar c = Calendar.getInstance();
int mYear = c.get(Calendar.YEAR);
int mMonth = c.get(Calendar.MONTH);
int mDay = c.get(Calendar.DAY_OF_MONTH);

DatePickerDialog dpd = new DatePickerDialog(this,
new DatePickerDialog.OnDateSetListener() {

public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {

//TextView txtDate = null;
txtDate.setText(dayOfMonth + "-" + (monthOfYear + 1)
+ "-" + year);
storeYear = year;storeMonth = monthOfYear;storeDay = dayOfMonth;

message("message", "Mensaje", mYear + "/" + mMonth + "/"
+ mDay, this, context);
}

public void onDateSet1(DatePicker view, int year,
int monthOfYear, int dayOfMonth) { // TODO
// Auto-generated
// method stub

}
}, mYear, mMonth, mDay);
dpd.show();

}

关于android - 在 Android 中创建模态日期选择器对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34359253/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com