如何使听者的datepickers在Android的取消按钮?

编程入门 行业动态 更新时间:2024-10-09 03:30:48
本文介绍了如何使听者的datepickers在Android的取消按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用Android中一个datepicker,让用户选择的日期。我想要它做的一件事,如果用户选择一个日期,并将其设置(我有工作的罚款),然后当用户按下取消按钮上的日期选择器(打开日期选择器,但随后取消了明确一定的文本字段它)。

I'm using a datepicker in Android to let the user to choose the date. I want it to do one thing if the user picks a date and sets it (I have that working fine) and then to clear a certain text field if the user pushes the cancel button on the datepicker (open up the datepicker but then cancel out of it).

我一直在努力的方式是通过一个

The way I've been trying is by making a

private DatePickerDialog.OnCancelListener mDateCancelListener = new DatePickerDialog.OnCancelListener() { public void onCancel(DialogInterface dialog) { timeClear(); //method that clears text field } };

然后我

TimePickerDialog timeDialog = new TimePickerDialog(this, mTimeSetListener, c.get(Calendar.HOUR), c.get(Calendar.MINUTE), false); timeDialog.setOnCancelListener(mTimeCancelListener);

附加监听器。

我的问题是,如果用户按下返回按钮听者的工作原理,但如果它们推取消按钮。我试图用解雇侦听器,这样的作品,除了它熄灭我甚至是否设置或取消的日期选择器!

My problem is that the listener works if the user pushes the back button, but not if they push the cancel button. I tried using a dismiss listener, and that works, except for the fact that it goes off even whether I set or cancel the datepicker!

什么我需要做的事情如此熄灭当且仅当我把我的日期选择取消按钮?

What do I need to do so something goes off if and only if I push the cancel button on my datepicker?

推荐答案

唯一的解决办法,直觉是,你需要覆盖的取消键:

The only solution, counter intuitive, is that you need to "override" the cancel button:

timeDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // do stuff } });

更多推荐

如何使听者的datepickers在Android的取消按钮?

本文发布于:2023-11-28 01:06:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1640362.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:听者   按钮   datepickers   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!