本文介绍了我想选择日历多个日期在android系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要选择日历多个日期,多选工作正常,但在吐司只显示。如果我选​​择了4天(1.8.14到4.8.14)单日(第一天)的所有日期应显示在祝酒。
这里是我的code


 公共类SampleTimesSquareActivity延伸活动{          私有静态最后弦乐TAG =SampleTimesSquareActivity;
          私人CalendarPickerView日历;
          私人AlertDialog theDialog;
          私人CalendarPickerView dialogView;
          公共静态日期JULY;          @覆盖
          保护无效的onCreate(捆绑savedInstanceState)
          {
                    super.onCreate(savedInstanceState);
                    的setContentView(R.layout.sample_calendar_picker);                   最终日历nextYear = Calendar.getInstance();
                    nextYear.add(Calendar.YEAR,1);                    最终日历lastYear = Calendar.getInstance();
                    lastYear.add(Calendar.YEAR,-1);                    历=(CalendarPickerView)findViewById(R.id.calendar_view);                    最终按钮多重=(按钮)findViewById(R.id.button_multi);                        今天的日历= Calendar.getInstance();                        today.set(Calendar.DAY_OF_MONTH,
                        today.getActualMaximum(Calendar.DAY_OF_MONTH));                        日期结束= today.getTime();
                        ArrayList的<日期和GT;日期=新的ArrayList<日期及GT;();
                        的for(int i = 0;我小于5;我++)
                        {
                          today.add(Calendar.DAY_OF_MONTH,3);
                          dates.add(today.getTime());
                        }
                        calendar.init(新的Date(),结束)//
                            .inMode(SelectionMode.MULTIPLE);
                    findViewById(R.id.done_button).setOnClickListener(新OnClickListener()
                    {
                          @覆盖
                          公共无效的onClick(查看视图)
                          {
                            Log.d(TAG,在米利斯选定的时间:+ calendar.getSelectedDate()的getTime());
                            字符串敬酒=选择日期:+ calendar.getSelectedDate();
                            Toast.makeText(SampleTimesSquareActivity.this,烤面包,LENGTH_SHORT).show();
                          }
                    });
          }          @覆盖公共无效onConfigurationChanged(配置NEWCONFIG)
          {
                    布尔applyFixes = theDialog = NULL&放大器;!&安培; theDialog.isShowing();
                    如果(applyFixes)
                    {
                      Log.d(TAG,配置变化:拔去了梦诗,所以我会得到重新测量!);
                      dialogView.unfixDialogDimens();
                    }
                    super.onConfigurationChanged(NEWCONFIG);
                    如果(applyFixes)
                    {
                      dialogView.post(新的Runnable()
                      {
                        @覆盖公共无效的run()
                        {
                          Log.d(TAG,配置变化来完成:重新修复梦诗!);
                          dialogView.fixDialogDimens();
                        }
                      });
                    }
          }
}


解决方案

一个快速谷歌说,有在CalendarPickerView的方法叫做 getSelectedDates()返回日期列表。这可能是你想要的。

更新的链接:https://github.com/square/android-times-square/blob/master/library/src/main/java/com/squareup/timessquare/CalendarPickerView.java

I want to select multiple dates in calendar,multiple select is working fine but in toast displaying only single date(first date).If I selected 4 days(1.8.14 to 4.8.14) all dates should be displayed in toast.here is my code


public class SampleTimesSquareActivity extends Activity{

          private static final String TAG="SampleTimesSquareActivity";
          private CalendarPickerView calendar;
          private AlertDialog theDialog;
          private CalendarPickerView dialogView;
          public static Date JULY;

          @Override
          protected void onCreate(Bundle savedInstanceState)
          {
                    super.onCreate(savedInstanceState);
                    setContentView(R.layout.sample_calendar_picker);

                   final Calendar nextYear = Calendar.getInstance();
                    nextYear.add(Calendar.YEAR, 1);

                    final Calendar lastYear = Calendar.getInstance();
                    lastYear.add(Calendar.YEAR, -1);

                    calendar = (CalendarPickerView) findViewById(R.id.calendar_view);

                    final Button multi = (Button) findViewById(R.id.button_multi);



                        Calendar today = Calendar.getInstance();

                        today.set(Calendar.DAY_OF_MONTH,
                        today.getActualMaximum(Calendar.DAY_OF_MONTH));

                        Date end = today.getTime();
                        ArrayList<Date> dates = new ArrayList<Date>();
                        for (int i = 0; i < 5; i++)
                        {
                          today.add(Calendar.DAY_OF_MONTH, 3);
                          dates.add(today.getTime());
                        }
                        calendar.init(new Date(),end) //
                            .inMode(SelectionMode.MULTIPLE);


                    findViewById(R.id.done_button).setOnClickListener(new OnClickListener()
                    {
                          @Override
                          public void onClick(View view)
                          {
                            Log.d(TAG, "Selected time in millis: " + calendar.getSelectedDate().getTime());
                            String toast = "Selected dates: " + calendar.getSelectedDate();
                            Toast.makeText(SampleTimesSquareActivity.this, toast, LENGTH_SHORT).show();
                          }
                    });
          }

          @Override public void onConfigurationChanged(Configuration newConfig)
          {
                    boolean applyFixes = theDialog != null && theDialog.isShowing();
                    if (applyFixes)
                    {
                      Log.d(TAG, "Config change: unfix the dimens so I'll get remeasured!");
                      dialogView.unfixDialogDimens();
                    }
                    super.onConfigurationChanged(newConfig);
                    if (applyFixes)
                    {
                      dialogView.post(new Runnable()
                      {
                        @Override public void run()
                        {
                          Log.d(TAG, "Config change done: re-fix the dimens!");
                          dialogView.fixDialogDimens();
                        }
                      });
                    }
          }
}
解决方案

A quick google says there is a method in CalendarPickerView called getSelectedDates() which returns a list of dates. This is probably what you want.

Updated link: https://github.com/square/android-times-square/blob/master/library/src/main/java/com/squareup/timessquare/CalendarPickerView.java

这篇关于我想选择日历多个日期在android系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 23:18