- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 DatePicker 对话框
。当一个按钮被点击时 datepicker show一切正常。
但是我的 BUTTON_NEGATIVE
按钮不起作用。我点击了 NEGATIVE_BUTTON
,diloagpicker 关闭但日期已设置。
这是我的 CalendarItem.java 文件:
public class CalendarItem extends DialogFragment implements DatePickerDialog.OnDateSetListener {
private Button pregnant_button;
private Button numbered_button;
public CalendarItem(Button pregnant_button) {
this.pregnant_button = pregnant_button;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
/*
tarih önceden ayarlanmışsa,
*/
long get_miliseconds_to_date = MotherActivity.preferences.getLong(MotherActivity.USER_DUE_DATE_MS,0);
final Calendar c = Calendar.getInstance();
if(get_miliseconds_to_date != 0 ) {
c.setTimeInMillis(get_miliseconds_to_date);
}
// Use the current date as the default date in the picker
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
DatePickerDialog dialog = new DatePickerDialog(getActivity(), this, year, month, day);
dialog.setButton(
DialogInterface.BUTTON_NEGATIVE, "Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if (which == DialogInterface.BUTTON_NEGATIVE) {
dialog.dismiss();
Log.d("Button_value","" + which + " ---- " + " negatif");
}
}
});
dialog.setButton(
DialogInterface.BUTTON_POSITIVE,"Set",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Log.d("Button_value","" + which + " ---- " + " Pozitif");
}
}
);
// Create a new instance of DatePickerDialog and return it
return dialog;
}
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
pregnant_button.setText(dayOfMonth + " " + MotherActivity.turkish_monts[monthOfYear] + " " + year);
long miliseconds_date = date_to_miliseconds(year, monthOfYear, dayOfMonth);
SharedPreferences.Editor editor = MotherActivity.preferences.edit();
editor.putLong(MotherActivity.USER_DUE_DATE_MS, miliseconds_date);
editor.apply();
}
private long date_to_miliseconds(int year, int month, int day){
Calendar calendar = Calendar.getInstance();
calendar.set(year,month,day,00,00);
return calendar.getTimeInMillis();
}
}
帮帮我。谢谢。
最佳答案
我很容易地解决了我的问题。
除了 bool 变量,我只添加了一行代码。
private Button pregnant_button;
//add this line default = false
private boolean printer = false;
public CalendarItem(Button pregnant_button) {
this.pregnant_button = pregnant_button;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
/*
tarih önceden ayarlanmışsa,
*/
long get_miliseconds_to_date = MotherActivity.preferences.getLong(MotherActivity.USER_DUE_DATE_MS,0);
final Calendar c = Calendar.getInstance();
if(get_miliseconds_to_date != 0 ) {
c.setTimeInMillis(get_miliseconds_to_date);
}
// Use the current date as the default date in the picker
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
DatePickerDialog dialog = new DatePickerDialog(getActivity(), this, year, month, day);
dialog.setButton(
DialogInterface.BUTTON_NEGATIVE, "İptal",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if (which == DialogInterface.BUTTON_NEGATIVE) {
}
}
});
dialog.setButton(
DialogInterface.BUTTON_POSITIVE, "Tamam",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if (which == DialogInterface.BUTTON_POSITIVE) {
printer = true;
}
}
});
// Create a new instance of DatePickerDialog and return it
return dialog;
}
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
if( printer ) {
pregnant_button.setText(dayOfMonth + " " + MotherActivity.turkish_monts[monthOfYear] + " " + year);
long miliseconds_date = date_to_miliseconds(year, monthOfYear, dayOfMonth);
SharedPreferences.Editor editor = MotherActivity.preferences.edit();
editor.putLong(MotherActivity.USER_DUE_DATE_MS, miliseconds_date);
editor.apply();
}
}
关于Android DatePickerDialog 取消按钮不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21527128/
有什么方法可以让 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
我是一名优秀的程序员,十分优秀!