辞退DatePickerDialog在pressing后退按钮 [英] Dismiss DatePickerDialog on pressing back button

查看:76
本文介绍了辞退DatePickerDialog在pressing后退按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我看来,我有一个按钮,当pressed弹出一个DatePickerDialog。该poppedup对话框中有一个完成按钮。当我preSS该按钮选定的日期是填充到一个EditText框。

On my view I have a button which when pressed pops up a DatePickerDialog. The poppedup dialog has a "Done" button. When I press that button the selected date is populated into an EditText box.

现在,当我preSS后退按钮(),它仍然填充的日期在EditText上。我如何关闭对话框,而不从它返回的任何值。

Now, when I press the back button (), it still populates the date in the EditText. How do I dismiss the dialog without returning any value from it.

这是code我有 -

This is code I've got-

它调用片段活动:

public class TransactionActivity extends FragmentActivity implements iRibbonMenuCallback {        
    .....
    public void selectDate(View view) { 
        // This is the method invoked by the button
        SelectDateFragment newFragment = new SelectDateFragment();
        newFragment.show(getSupportFragmentManager(), "DatePicker");
    }

    public void populateSetDate(int year, int month, int day) {
        // Puts the date in the EditText box
        mEdit = (EditText)findViewById(R.id.DateText);
        mEdit.setText(month+"/"+day+"/"+year);
    }
}

一个片段的对话框(基于页面在Android API指南):

A fragment for the Dialog (based on this page on Android API guides):

public class SelectDateFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        final Calendar calendar = Calendar.getInstance();
        int yy = calendar.get(Calendar.YEAR);
        int mm = calendar.get(Calendar.MONTH);
        int dd = calendar.get(Calendar.DAY_OF_MONTH);
        return new DatePickerDialog(getActivity(), this, yy, mm, dd);
    }

    public void onDateSet(DatePicker view, int yy, int mm, int dd) {
             // Calls a method on the activity which invokes this fragment
         ((TransactionActivity)getActivity()).populateSetDate(yy, mm+1, dd);    

    }
}

似乎没有被处理的情况下没有设置类似的数据与onDataSet的方法。

There doesn't seem to be a method analogous with onDataSet for handling the case when data was not set.

有没有办法来取消/关闭该弹出日期选择器没有得到它的价值呢?

Is there a way to cancel/dismiss the popped up datepicker without getting it's value?

感谢。

推荐答案

它看起来像有与Jelybean不工作了一个错误的取消按钮(安培;因此,后退按钮)。这在<一个讨论href="http://stackoverflow.com/questions/11444238/jelly-bean-datepickerdialog-is-there-a-way-to-cancel/">Jelly豆DatePickerDialog ---有没有办法取消?

It looks like there is a bug with Jelybean where the Cancel button isn't working(& hence the back button). This is discussed in Jelly Bean DatePickerDialog --- is there a way to cancel?

大卫Cesarino ,谁报告了上述职位的缺陷和解决办法,公布他的解决方案的这里和<一href="http://stackoverflow.com/questions/11444238/jelly-bean-datepickerdialog-is-there-a-way-to-cancel/11493752#11493752">SO.

David Cesarino, who reported the bug and workaround in the above post, posted his solution here and SO.

cavega 的稍微修改上述溶液中,以允许的日期在DatePickerDialog比今天的日期的东西等的初始化。 code可以在这里找到 。我用自己的解决方案,并得到它的工作。

cavega slightly modified the above solution to allow initialization of the date in the DatePickerDialog to something other than today's date. Code can be found here. I used his solution and got it to work.

这篇关于辞退DatePickerDialog在pressing后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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