【问题标题】:Android custom calendar view disable specific datesAndroid自定义日历视图禁用特定日期
【发布时间】:2015-06-22 08:19:07
【问题描述】:

我是 android 开发的新手,并开始开发预订应用程序。有一个日历视图,我想禁用该日历中的预订日期。我发现android默认日历中没有禁用功能。所以你能帮我找到一个可以禁用特定日期的好的自定义日历视图吗?我需要资源或图书馆。谢谢!

【问题讨论】:

标签: android calendarview


【解决方案1】:

在布局 XML 中包含 CalendarPickerView。

<com.squareup.timessquare.CalendarPickerView
android:id="@+id/calendar_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

在活动/对话框的 onCreate 或片段的 onCreateView 中,使用有效日期范围以及当前选择的日期初始化视图。

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

CalendarPickerView calendar = (CalendarPickerView) findViewById(R.id.calendar_view);
Date today = new Date();
calendar.init(today, nextYear.getTime()).withSelectedDate(today);

github链接-https://github.com/square/android-times-square

【讨论】:

  • 你用过这个日历吗?有一种方法可以突出显示日期但禁用日期。我可以为禁用日期做任何事情,这样用户就无法选择那些禁用日期!!!
  • @user2214782 我就是这样做的stackoverflow.com/questions/29764521/…
  • @maveň 在这里您只能禁用从最小日期到最大日期。我需要知道如何禁用日期数组。
  • @DwivediJi 解释更多
  • 如何将所有星期日设置为从 minDate 到 maxDate 的取消选择日期,并且所有假期都应取消选择请回复,但我使用 github.com/roomorama/Caldroid
【解决方案2】:
i have faced the same problem using custom calendar ,
i just overridden the function of adapter 


 @Override
    public boolean isEnabled(int position) {
         if(mySet.contains(position))
            return true;
        else
            return false;
    }


then i call the function int the adapter view 

 isEnabled(position);




befoer that tale Hashset and add the position which is displaying the calanderview 


           // mysetSize=set.size();
            //isEnabled(Integer.parseInt(gridvalue));
            Log.d(dayView.getTag()+"------1-------"+gridvalue,"-------"+position);
        } else if ((Integer.parseInt(gridvalue) < 7) && (position > 28)) {
            dayView.setTextColor(Color.WHITE);
            dayView.setClickable(false);
            dayView.setFocusable(false);
            Log.d("-------mySet------","-------"+mySet);
            Log.d(mysetSize+"-------28------"+gridvalue,"-------"+position);
            set.add(position);

        } else {
            // setting curent month's days in blue color.
            dayView.setTextColor(Color.DKGRAY);
            Log.d(dayView.getTag()+"-------current display post------","-------"+position);
            mySet.add(position);
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多