【问题标题】:Android:DatePickerdialog with Cancel button [duplicate]Android:带有取消按钮的DatePickerdialog [重复]
【发布时间】:2013-03-02 14:49:43
【问题描述】:

我正在处理datepicker 对话框,我面临的一个问题是选择器上有取消按钮(android jelly bean 没有取消按钮)。现在问题还在于我的日期选择器对话框在按钮上被调用(在listview 适配器类中)按下。在适配器类中我使用 date_picker_id 概念。任何帮助将不胜感激。

((Activity) LessonListViewAdapter.this.context).showDialog(DATE_DIALOG_ID);

这会调用Activity中的createdialog函数。

【问题讨论】:

    标签: android android-4.2-jelly-bean


    【解决方案1】:

    Jelly Bean DatePickerDialog --- is there a way to cancel? 链接中的答案为您提供了解决方法。我发现此链接试图回答有关数据选择器的问题之一。

    看起来这是一个错误,其他人已经填补了它。http://code.google.com/p/android/issues/detail?id=34833。链接中的答案为您提供了解决方法。

    编辑1

    public static final int TIME_DIALOG_ID = 1;
    public static final int DATE_DIALOG_ID = 2;
    
    @Override
    protected Dialog onCreateDialog(int id) {
    
    switch (id) {
    case DATE_DIALOG_ID:
    // set date picker as current date
    myDialog = new DatePickerDialog(this, datePickerListener, year, month,day);
    break;
    
    case TIME_DIALOG_ID:
    //set time picker as current time
    myDialog = new TimePickerDialog(this, timePickerListener, hour, minute,false);
    break;
    
    }
    
    return myDialog;       
    }
    

    【讨论】:

    • 我已经浏览了这两个链接,但这并没有解决我的问题。我正在从 oncreatedialog 函数创建日期选择器对话框。
    • protected Dialog onCreateDialog(int id) { switch (id) { case DATE_DIALOG_ID: return new DatePickerDialog(Activity.this, dateListener, pYear, pMonth, pDay); } 返回空值; }
    • 至少你有办法解决取消按钮问题。它也应该适用于您的情况。
    • 您能否发布更多关于您所做工作的代码
    • 在每个 case 之后也使用 break。你有什么错误吗??
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-23
    • 2012-07-05
    • 1970-01-01
    • 2014-02-08
    • 1970-01-01
    相关资源
    最近更新 更多