如何检测取消点击datepicker对话框? [英] How do I detect a cancel click of the datepicker dialog?

查看:127
本文介绍了如何检测取消点击datepicker对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下
日期选择器的示例



http://developer.android.com/guide/tutorials/views/hello-datepicker.html



现在我想执行一些功能点击日期选择器取消按钮,但没有看到在datepickerdialog内取消事件



可以任何人指导我如何实现这一点。 p>

任何帮助将不胜感激。

解决方案

  DatePickerDialog dialog = new DatePickerDialog(this,
mDateSetListener,
year,month,day);

dialog.setButton(DialogInterface.BUTTON_NEGATIVE,getString(R.string.cancel),new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,int which){
if(which == DialogInterface.BUTTON_NEGATIVE){
// Do Stuff
}
}
});


i am using following example of date picker

http://developer.android.com/guide/tutorials/views/hello-datepicker.html

now i want to perform some functionality on clicking date picker cancel button but dont see cancel event inside datepickerdialog

can any one guide me how to achieve this.

any help would be appreciated.

解决方案

Here's how I did it:

  DatePickerDialog dialog = new DatePickerDialog(this,
              mDateSetListener,
              year, month, day);

  dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.cancel), new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int which) {
       if (which == DialogInterface.BUTTON_NEGATIVE) {
          // Do Stuff
       }
    }
  });

这篇关于如何检测取消点击datepicker对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆