多个日期选择器对话框
我的 Activity 类中有 4 个 DatePicker 对话框,单击 4 个按钮即可显示它们。现在对于这些 datePickerDialog 我想使用相同的侦听器。
DatePickerDialog taxPickerDialog = new DatePickerDialog(getCurrentContext(),dateSetListener,calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),calendar.get(Calendar.DATE));
taxPickerDialog.show();
DatePickerDialog fcPickerDialog = new DatePickerDialog(getCurrentContext(),dateSetListener,calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),calendar.get(Calendar.DATE));
fcPickerDialog.show();
break;
DatePickerDialog expiryPickerDialog = new DatePickerDialog(getCurrentContext(),dateSetListener,calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),calendar.get(Calendar.DATE));
expiryPickerDialog.show();
DatePickerDialog permitPickerDialog = new DatePickerDialog(getCurrentContext(),dateSetListener,calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),calendar.get(Calendar.DATE));
permitPickerDialog.show();
现在我想要一个使用侦听器,但不知道如何实现这个???
DatePickerDialog.OnDateSetListener dateSetListener =new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int day) {
switch(????){????}
}
};
I have 4 DatePicker Dialog in my Activity Class which are shown on click of 4 buttons . Now for these datePickerDialog i want to use same listener .
DatePickerDialog taxPickerDialog = new DatePickerDialog(getCurrentContext(),dateSetListener,calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),calendar.get(Calendar.DATE));
taxPickerDialog.show();
DatePickerDialog fcPickerDialog = new DatePickerDialog(getCurrentContext(),dateSetListener,calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),calendar.get(Calendar.DATE));
fcPickerDialog.show();
break;
DatePickerDialog expiryPickerDialog = new DatePickerDialog(getCurrentContext(),dateSetListener,calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),calendar.get(Calendar.DATE));
expiryPickerDialog.show();
DatePickerDialog permitPickerDialog = new DatePickerDialog(getCurrentContext(),dateSetListener,calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),calendar.get(Calendar.DATE));
permitPickerDialog.show();
Now i want a use listener but dnot know how to implement this ???
DatePickerDialog.OnDateSetListener dateSetListener =new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int day) {
switch(????){????}
}
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
并在您的日期选择器视图中注册此侦听器。确保此类是您活动的内部类
and register this listener in your datepicker views., make sure this class is inner class of your activity
希望您现在已经解决了这个问题。只是提出一个想法 - “您可以为与每个
Dialog
关联的DatePicker
设置某种ID
或TAG
并且然后您可以通过查询您设置的(ID/TAG)
来区分。”Hope you might have resolved this by now. Just putting an idea - "you can set some sort of
ID
orTAG
forDatePicker
associated with eachDialog
and then you can differentiate by querying what you have set(ID/TAG)
."我知道回复晚了,但我最近也遇到了同样的情况。所以这是我的答案,
方法
是为 Fragment 本身设置标签。所以这个标签可以按如下方式使用:
一个用例是您可以在活动中显示多个
Fragment
并识别该片段,您可以找到具有给定标签的片段。如果它不为空,宾果!!!I know its a late reply but i went through with the same condition recently . So here is my answer ,
the
method is set tag for Fragment itself . so this tag can be use as follows :
one use case is you can display more then one
Fragment
in a activity and to identify the fragment you can find that fragment with the given tag.If it is not null, bingo!!!