显示的DatePicker与其他日历系统日历、与其他、系统、DatePicker

2023-09-07 15:15:10 作者:花逝 ╮

我有一个日期选择在自定义对话框并没有显示日期,用户可以选择日期,我得到了用户选择的日期。现在我想通过显示其他日历走得更远

有关如波斯日历日期,而不是​​公历日历日期。现在,当用户选择的日期选择器的日期我的应用程序,我可以返回波斯日在日志中。但我不知道如何改变的DatePicker显示perisan date.please帮助。

  @覆盖
 公共布尔onCreateOptionsMenu(菜单菜单)
 {
    menu.add(添加详细信息)的setIcon(R.drawable.ic_compose).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT)。
    返回true;
 }

 @覆盖
 公共布尔onOptionsItemSelected(菜单项项)
 {
    最后一个对话框对话框=新的对话框(本);
    dialog.setContentView(R.layout.custom);

    最后的EditText额=(EditText上)dialog.findViewById(R.id.amtEditText);
    最后的DatePicker日期选择器=(DatePicker的)dialog.findViewById(R.id.datePicker1);
    按钮cancelButton =(按钮)dialog.findViewById(R.id.canelButton);
    按钮OKButton =(按钮)dialog.findViewById(R.id.OKbutton);

    OKButton.setOnClickListener(新View.OnClickListener()
    {
        @覆盖
        公共无效的onClick(视图v)
        {
            Log.d(---------------,datePicker.getDayOfMonth()+
                                   + datePicker.getMonth()+
                                   + datePicker.getYear()+
                                   + amount.getText());

            Toast.makeText(MainActivity.this,得到点击:
                                 + datePicker.getDayOfMonth()+
                                 + datePicker.getMonth()+
                                 + datePicker.getYear(),Toast.LENGTH_SHORT).show();

            CivilDate民间=新CivilDate(datePicker.getYear(),datePicker.getMonth(),datePicker.getDayOfMonth());
            PersianDate perDate = DateConverter.civilToPersian(民事);

            Log.d(-------,perDate.getDayOfMonth()++(perDate.getMonth()+ 1)++ perDate.getYear()++ perDate.getMonthName() );
            datePicker.init(perDate.getYear(),(perDate.getMonth()+1),perDate.getDayOfMonth(),空);
        }
    });
 

解决方案

而不是使用的DatePicker 切换到使用的 Android的车轮库。 这是写由谷歌开发,它可以设置样式看起来像Android的的DatePicker 还提供了一致的外观和感觉上的旧手机。

这不是由你可以把什么样的领域要么这意味着你可以使用任何你想要的限制。

iOS源码 日历之封装的My97DatePicker日历

I have a Datepicker in a custom Dialog which shows the date and the user can select the date and I get the user selected date. Now I want to go further by showing other calendar

for e.g. Persian calendar date instead of the Gregorian calender date. Now in my app when the user selects the date from the datepicker I can return the Persian date in the log. but I don't know how to change the DatePicker to show perisan date.please help.

 @Override
 public boolean onCreateOptionsMenu(Menu menu)
 {
    menu.add("Add Detail").setIcon(R.drawable.ic_compose).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
    return true;
 }

 @Override
 public boolean onOptionsItemSelected(MenuItem item)
 {
    final Dialog dialog = new Dialog(this);
    dialog.setContentView(R.layout.custom);

    final EditText amount = (EditText) dialog.findViewById(R.id.amtEditText);
    final DatePicker datePicker = (DatePicker) dialog.findViewById(R.id.datePicker1);
    Button cancelButton = (Button) dialog.findViewById(R.id.canelButton);
    Button OKButton = (Button) dialog.findViewById(R.id.OKbutton);

    OKButton.setOnClickListener(new View.OnClickListener() 
    {
        @Override
        public void onClick(View v) 
        {
            Log.d("---------------", datePicker.getDayOfMonth() +" " 
                                   + datePicker.getMonth() + " " 
                                   + datePicker.getYear() + " " 
                                   + amount.getText());

            Toast.makeText(MainActivity.this, "Got click: "
                                 + datePicker.getDayOfMonth() + " " 
                                 + datePicker.getMonth() + " " 
                                 + datePicker.getYear(), Toast.LENGTH_SHORT).show();

            CivilDate civil = new CivilDate(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth());
            PersianDate perDate = DateConverter.civilToPersian(civil);

            Log.d("-------", perDate.getDayOfMonth()+ " " + (perDate.getMonth() + 1) + " " + perDate.getYear() + " " + perDate.getMonthName());
            datePicker.init(perDate.getYear(), (perDate.getMonth() + 1), perDate.getDayOfMonth(), null);
        }
    });

解决方案

Instead of using the DatePicker switch to using the Android Wheel library. It's written by a Google Developer and it can be styled to look like the Android DatePicker it also provides consistent look and feel on older phones.

It's not restricted by what you can put in the fields either which means you can use anything you want.