gpt4 book ai didi

java - Android 日期选择器监听器不能工作超过一次..

转载 作者:行者123 更新时间:2023-11-29 09:08:41 31 4
gpt4 key购买 nike

我有一个 Activity ,其中我有两个日期选择器,首先我通过这些语句初始化它们

    public class birthDate extends Activity{

Calendar c = Calendar.getInstance();
int currentYear = c.get(Calendar.YEAR);
int currentMonth = c.get(Calendar.MONTH);
int currentDay = c.get(Calendar.DAY_OF_MONTH);
public void onCreate(Bundle savedInstanceState)
{

super.onCreate(savedInstanceState);

setContentView(R.layout.birthdate);

DatePicker birthDayDatePicker,periodDatePicker;
birthDayDatePicker = (DatePicker)findViewById(R.id.DatePickerBirthDay);
periodDatePicker = (DatePicker)findViewById(R.id.DatePickerPeriod);
periodDatePicker.init(currentYear, currentMonth, currentDay, new OnDateChangedListener()
{

@Override
public void onDateChanged(DatePicker arg0, int arg1, int arg2,int arg3) {
// TODO Auto-generated method stub
birthDateCalculations();
}
});

birthDayDatePicker.init(currentYear, currentMonth, currentDay, new OnDateChangedListener() {

@Override
public void onDateChanged(DatePicker arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub

periodDateCalculations();

}
});

}}

我意识到那些监听器只发生了一次,就好像我再次点击了日期选择器一样,语句将不会被应用..我想要一种方法,让监听器在我每次单击日期选择器时都处于 Activity 状态。

提前致谢!

最佳答案

请在 Activity 的oncreate 方法中初始化选择器。

关于java - Android 日期选择器监听器不能工作超过一次..,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13507394/

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