Android 日历选择器使用 您所在的位置:网站首页 android日历 Android 日历选择器使用

Android 日历选择器使用

2023-04-10 15:03| 来源: 网络整理| 查看: 265

1.实现效果

布局上是RecyclerView嵌套RecyclerView,上面2018年月9月是通过自定义RecyclerView.ItemDecoration绘制,代码下面地址有,这里就不解说自定义RecyclerView.ItemDecoration了

((DefaultItemAnimator) mBinding.rv.getItemAnimator()).setSupportsChangeAnimations(false);

//当前日期转date

SimpleDateFormat ymd_sdf=new SimpleDateFormat("yyyy-MM-dd");

try {

if(currentDate==null){

new Throwable("please set one start time");

return;

}

mSetDate = ymd_sdf.parse(currentDate);

} catch (ParseException e) {

e.printStackTrace();

}

//修改日历对象的日期

Calendar c = Calendar.getInstance();

c.setTime(mSetDate);

//获取月份 月份是从0开始需要+1

int firstM= c.get(Calendar.MONTH)+1;

//日期

int days=c.get(Calendar.DATE);

//周几

int week=c.get(Calendar.DAY_OF_WEEK);

//获取当前这个月最大天数

int maxDys=c.getActualMaximum(Calendar.DAY_OF_MONTH);

int startDate=0;

//日 一 二 三 四 五 六

//- - 当前

//需要求上周末的日期(周末到周一的日期)填补

if("1".equals(week+"")){

//今天是否周末

startDate=days;

}else {

//获取上周末

startDate= Integer.parseInt(CalendarUtil.getPreviousWeekSundayByDate(ymd_sdf.format(mSetDate)).split("-")[2]);

}

DateInfo info = new DateInfo();

List dayList=new ArrayList();

info.setDate(c.get(Calendar.YEAR)+ "年" + firstM + "月");

//根据周末日期开始计算到结尾日期的天数

//当小于当前日期时,是不可选,setEnable(false)

//如果上周末是大于当前的,说明上周末是上个月的

//如何判断呢,1,当前日期小于周末则是上个月 2,其他情况是当前日期肯定会大于周末

if(days



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有