- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在使用 DialogFragment 在 onCreateDialog() 中返回 DatePickerDialog。我已将 dateSetListener 设置为 DialogFragment(在下面的示例中为“this”)并且一切正常,除了在发生屏幕旋转时调用 onDateSet(),这是不希望的。如何让 onDateSet 在屏幕旋转时不被调用?
我的 DialogFragment
public static class DateDialogFragment extends DialogFragment implements
DatePickerDialog.OnDateSetListener{
public static DateDialogFragment newInstance() {
return new DateDialogFragment();
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new DatePickerDialog(getActivity(), this, 2012, 11, 19);
}
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
//This is called when screen rotated, which I dont want
Toast.makeText(getActivity(), "Year: "+year+" Month: "+monthOfYear+" Day: "+dayOfMonth, Toast.LENGTH_SHORT).show();
}
}
我就是这样调用它的
if(getActivity()!=null){
FragmentManager fm = getActivity().getSupportFragmentManager();
DialogFragment newFragment = DateDialogFragment.newInstance();
newFragment.show(fm, "dialog");
}
最佳答案
在onDateSet
方法中,使用Activity::isChangingConfigurations 检查Activity
是否因配置更改而重新启动。 .如果是,则不显示 Toast
。
@Override
public void onDateSet(android.widget.DatePicker view, int year, int monthOfYear, int dayOfMonth) {
if( ! this.getActivity().isChangingConfigurations() ) {
// Dialog is dismissed by user explicitly, hence show the Toast message.
Toast.makeText(getActivity(), "Year: "+year+" Month: "+monthOfYear+" Day: "+dayOfMonth, Toast.LENGTH_SHORT).show();
}
}
我已经对其进行了测试并且运行良好。如果需要任何进一步的帮助,请告诉我。
关于android - 旋转时调用 DatePickerDialog onDateSet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13959164/
有什么方法可以让 DatePickerDialog 在点击设置按钮后不消失吗? 最佳答案 为对话框按钮添加一个 OnClickListener 并覆盖 onClick。 关于安卓 DatePicker
所有编写的DatePickerDialog都报错(无法解析符号),但程序编译正确,LogCat中没有错误。谁能解释一下为什么? 最佳答案 您应该尝试文件菜单上的无效缓存/重新启动选项。过时的缓存是导致
我已将 DatePickerDialog 包含到我的 Activity 中,它允许用户选择日历月份和日期。但是,我想将选择限制为从现在起一周以内(当前日期之前没有选项)。 我已经研究过setMinDa
我正在使用DatePickerDialog它就像一个魅力。现在我想将 3 个字符串数组 (array.xml) 中的自己的值设置到日期选择器中。原因是我正在更改应用程序内部的区域设置,而不是整个手机。
底部的两个按钮不会显示标签。这就是我实例化日期选择器 new DatePickerDialog(classname.this, date, myCalendar .get(Calendar.YEAR)
我正在使用 DatePickerDialog 选择日期。当月份从一周的最后一天开始,并且有 31 天时,不显示该月的最后一天。例如 2019 年 12 月从星期日开始,不显示日期 30 和 31。 我
这个问题在这里已经有了答案: Customize DatePicker. Android (2 个答案) 关闭 9 年前。 我想更改适合品牌的 DatePicker 颜色。我该怎么做? 此外,我想在
我发现了一些奇怪的事情: 我们来看看正常的DatePickerDialog: 当我添加这一行来设置昨天的最大日期时: datePickerDialog.getDatePicker().setMaxDa
我目前正在我的 Android 应用程序中使用 DatePickerDialog。 众所周知,对话框有三个 EditText:1) 天 2) 月 3) 年。并且有 + 和 - 三个按钮可以移动到所选字
我有一个 EditView,我试图在其中绑定(bind) DatePickerDialog。它与 api 19 配合良好。但是当在 api version 25 Marshmallow 上测试时,日历
我正在尝试在我的 android 应用程序中实现一个日期选择器,但是我似乎找不到 DatePickerDialog 界面。 public class DatePickerFragment extend
我已经实现了 DatePickerDialog,它可以正常工作。但是,标题似乎没有格式。例如,它应该显示为:2011 年 4 月 12 日,星期二。但它显示为 3, 2011 4 12。 源代码看起来
我正在制作一个使用 DatePickerDialog 的 Android 应用程序。预期的功能是让用户在对话框中选择一个日期,然后让 TextView 反射(reflect)所选日期。但是,当用户选择
我想我只是一个小错误,但我找不到它。在下面的代码中,我的整个 @Override 方法被标记为“false”。 inputBill.setOnFocusChangeListener(n
我创建了一个 DatePickerDialog 并传递了自定义年份、日期、日期(例如,我已经传递了 2017 年 1 月 26 日)。它显示所有年份的 1 月 26 日都突出显示。我怎样才能避免这种情
我已经在我的应用程序中实现了 DatePickerDialog,但只有 Lollipop 存在以下问题。 代码 fragment : void setDate(final EditText ed) {
我正在使用 DatePicker 对话框。当一个按钮被点击时 datepicker show一切正常。 但是我的 BUTTON_NEGATIVE 按钮不起作用。我点击了 NEGATIVE_BUTTON
我有一个奇怪的问题。我从 AppCompatActivity 继承了 Activity,里面有 Fragment。在这个 Fragment 中,我显示了 DatePickerDialog 来选择日期。
我正在使用以下代码从 EditText 创建一个 DatePickerDialog。 import android.widget.DatePicker; import android.app.Date
我已经为 DatePickerDialog 背景设置了样式,它在 Nexus 5 (Marshmallow) 上的显示方式有所不同: 我使用的样式是: @color/android:whit
我是一名优秀的程序员,十分优秀!