Android How to avoid weekend from android default date picker

戏子无情 提交于 2019-12-08 05:23:29

问题


I want to make a custom date picker in Android which will only show weekdays i.e. Monday to Friday, skipping week-end. looking for some help to start with.


回答1:


Take a look at this project.

In this case he only removed Sundays but you can adjust it to remove Saturdays also, like this:

  if (choosenDate.get(Calendar.DAY_OF_WEEK) == 
                    Calendar.SUNDAY || Calendar.DAY_OF_WEEK) == 
                    Calendar.SATURDAY ||
                    now.compareTo(choosenDate) < 0) {
                    dateTextView.setTextColor(
                        Color.parseColor("#ff0000")
                    );
                    ((Button) dialog.getButton(
                    AlertDialog.BUTTON_POSITIVE))
                        .setEnabled(false);
                }

Hope it helps.

*he just prevented the user from choose them, but I think you can hide it like this inside your if:

    dateTextView.setVisibility(View.GONE);


来源:https://stackoverflow.com/questions/19643493/android-how-to-avoid-weekend-from-android-default-date-picker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!