gpt4 book ai didi

java - 想要在日期选择器上选择上一个日期。 (安卓)

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

我在自定义对话框中有一个日期选择器和一个时间选择器。如果我更改日期选择器上的日期,它会在 Textview 上更新。但是当我再次选择日期选择器时,它给出了今天的日期。我希望之前选择的日期显示在日期选择器上。这是我的代码。请帮忙!!

from.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {
// TODO Auto-generated method stub

picker = new Dialog(getActivity());
picker.setContentView(R.layout.datetime);
picker.setTitle("Select Date and Time");
datep = (DatePicker) picker.findViewById(R.id.datePicker);
timep = (TimePicker) picker.findViewById(R.id.timePicker1);

set = (Button) picker.findViewById(R.id.btnSet);
set.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// TODO Auto-generated method stub
month = datep.getMonth() + 1;
day = datep.getDayOfMonth();
year = datep.getYear();
hour = timep.getCurrentHour();
minute = timep.getCurrentMinute();
from.setText(year + "-" + month + "-" + day + " "
+ hour + ":" + minute);
picker.dismiss();



}
});
picker.show();
}
});

最佳答案

找到了答案。只需将其设置在显示按钮的按钮范围之外...

    picker = new Dialog(getActivity());
picker.setContentView(R.layout.datetime);
picker.setTitle("Select Date and Time");
datep = (DatePicker) picker.findViewById(R.id.datePicker);
timep = (TimePicker) picker.findViewById(R.id.timePicker1);


from.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {
// TODO Auto-generated method stub

set = (Button) picker.findViewById(R.id.btnSet);
set.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// TODO Auto-generated method stub


//datep.updateDate(year, month, day);

month = datep.getMonth() + 1;
day = datep.getDayOfMonth();
year = datep.getYear();
hour = timep.getCurrentHour();
minute = timep.getCurrentMinute();
from.setText(year + "-" + month + "-" + day + " "
+ hour + ":" + minute);
picker.dismiss();



}
});
picker.show();
}
});

关于java - 想要在日期选择器上选择上一个日期。 (安卓),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24608991/

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