android 日期选择自定义popwindow实现90天内展示

日期选择器

android 可放入项目中直接使用、并可改变背景以及字体颜色等属性;

#核心代码块

/** 取消订单弹窗 */
private void popReason(){
// 一个自定义的布局,作为显示的内容
View contentView = LayoutInflater.from(mactivity).inflate(R.layout.pop_dateselecter_details, null);
pop_showDatePicker = new PopWindow(contentView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
pop_showDatePicker.setBackgroundDrawable(getResources().getDrawable(R.color.tming));
pop_showDatePicker.setTouchable(true);
pop_showDatePicker.setOutsideTouchable(true);
pop_showDatePicker.setFocusable(true);

    RelativeLayout rl_left,rl_right;    ImageView left,right;    TextView click;    rl_left = contentView.findViewById(R.id.rl_left);    rl_right = contentView.findViewById(R.id.rl_right);    left = contentView.findViewById(R.id.iv_left);    right = contentView.findViewById(R.id.iv_right);    chooseYM = contentView.findViewById(R.id.tv_chooseYM);    click = contentView.findViewById(R.id.tv_orther);    mgv_date = (MyGridView) contentView.findViewById(R.id.mgv_date);    right.setEnabled(false);    mgv_date.setOnItemClickListener(new AdapterView.OnItemClickListener() {        @Override        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {            TimeChooseInfo timeChooseInfo = (TimeChooseInfo) parent.getItemAtPosition(position);            if(timeChooseInfo.isGray()){                return;            }            chooseDay = timeChooseInfo.getDay();            adapter_date.chooseindexYM = chooseyearmonth;            adapter_date.refreshDate(listchangedate,chooseyearmonth, chooseDay);            pop_showDatePicker.dismiss();        }    });    rl_left.setOnClickListener(new View.OnClickListener() {        @Override        public void onClick(View v) {            right.setEnabled(true);//开启右边点击            right.setImageResource(R.mipmap.timegorighta);            if(chooseOne >= listmonthday.size()-1){                left.setEnabled(false);//关闭左边点击                return;            }            chooseOne += 1;            if(chooseOne == listmonthday.size()-1){//已到最左边                left.setImageResource(R.mipmap.timegoleft);            }else{                left.setImageResource(R.mipmap.timegolefta);            }            listdate.clear();            chooseyearmonth = listmonthday.get(chooseOne).substring(0,listmonthday.get(chooseOne).length()-3);            chooseYM.setText(TextUtils.isEmpty(chooseyearmonth)?"****年**月":Utils.getTimeYM(chooseyearmonth));            listdate.addAll(TimeUtils.getchooseDays(listmonthday.get(chooseOne)));            changeListTime(0);            adapter_date.refreshDate(listchangedate,chooseyearmonth,chooseDay);        }    });    rl_right.setOnClickListener(new View.OnClickListener() {        @Override        public void onClick(View v) {            left.setEnabled(true);            left.setImageResource(R.mipmap.timegolefta);            if(chooseOne <= 0){                right.setEnabled(false);                return;            }            chooseOne -= 1;            if(chooseOne == 0){//已到最右边                right.setImageResource(R.mipmap.timegoright);            }else{                right.setImageResource(R.mipmap.timegorighta);            }            listdate.clear();            chooseyearmonth = listmonthday.get(chooseOne).substring(0,listmonthday.get(chooseOne).length()-3);            chooseYM.setText(TextUtils.isEmpty(chooseyearmonth)?"****年**月":Utils.getTimeYM(chooseyearmonth));            if(chooseOne == 0){                listdate.addAll(TimeUtils.getchooseLastDays(listmonthday.get(chooseOne)));            }else{                listdate.addAll(TimeUtils.getchooseDays(listmonthday.get(chooseOne)));            }            if(chooseOne == 0){                changeListTime(1);            }else{                changeListTime(0);            }            adapter_date.refreshDate(listchangedate,chooseyearmonth,chooseDay);        }    });    click.setOnClickListener(new View.OnClickListener() {        @Override        public void onClick(View v) {            pop_showDatePicker.dismiss();        }    });}

#逻辑处理

/**
*
* 近多少天的日期
* @param maxShowDay
*/
private void getAdaptData(int maxShowDay){
listmonthday = TimeUtils.getDateList(maxShowDay);
Log.e(“shul”,listmonthday.size()+“个”);
if(listmonthday.size()>0){
chooseOne = 0;
chooseyearmonth = listmonthday.get(0).substring(0,listmonthday.get(0).length()-3);
chooseDay = listmonthday.get(0).substring(listmonthday.get(0).length()-2);
listdate = TimeUtils.getchooseLastDays(listmonthday.get(0));
changeListTime(1);
chooseYM.setText(TextUtils.isEmpty(chooseyearmonth)?"****年**月":Utils.getTimeYM(chooseyearmonth));
Utils.ShowLog(chooseyearmonth);
Utils.ShowLog(chooseDay);
}
if(adapter_date == null){
adapter_date = new DateChooseAdapter(mactivity,listchangedate,chooseyearmonth,chooseDay);
mgv_date.setAdapter(adapter_date);
}else{
adapter_date.refreshDate(listchangedate,chooseyearmonth,chooseDay);
}
}

/** * 转换对象处理灰色不可点击 * @param type 0:其他月  1: 当前月往后加 */private void changeListTime(int type){//getMontyDay    listchangedate.clear();    int week = 0;//前面空格    //加正常操作的项    for (int i = 0; i < listdate.size(); i++) {        if(TextUtils.isEmpty(listdate.get(i))){            week += 1;        }else{            TimeChooseInfo timeChooseInfo = new TimeChooseInfo();            timeChooseInfo.setGray(false);            timeChooseInfo.setDay(listdate.get(i));            listchangedate.add(timeChooseInfo);        }    }    //灰色不可点击天数    int gradays = TimeUtils.getMontyDay(chooseyearmonth)-listchangedate.size();    Utils.ShowLog("灰色点击数量="+gradays);    //加灰色不可点击    for (int i = 0; i < gradays; i++) {        TimeChooseInfo timeChooseInfo = new TimeChooseInfo();        timeChooseInfo.setGray(true);        if(type == 1){            timeChooseInfo.setDay((Integer.parseInt(listdate.get(listdate.size()-1))+i+1)+"");            listchangedate.add(timeChooseInfo);        }else{            timeChooseInfo.setDay((gradays-i)+"");            listchangedate.add(0,timeChooseInfo);        }    }    //加计算周后的空格数    for (int i = 0; i < week; i++) {        TimeChooseInfo timeChooseInfo = new TimeChooseInfo();        timeChooseInfo.setGray(true);        timeChooseInfo.setDay("");        listchangedate.add(0,timeChooseInfo);    }}

#工具类 附件见

大家使用时,有个别背景样式 或布局 可自己自定义发挥、、、—————__Amity

#附件 链接 日期自定义选择器相关文件demo

更多相关文章

  1. 使用Eclipse开发Android
  2. Android之键盘点击事件
  3. android点击系统通知Notification,进入指定的activity
  4. Android之键盘点击事件
  5. Android(安卓)kotlin使用注解实现防按钮连点功能
  6. Android中对话框的工具类
  7. Android仿WIN8系统磁贴点击下沉倾斜效果
  8. android >ToggleButton(开启/关闭) 控件
  9. Android(安卓)studio的点击事件

随机推荐

  1. Android入门2—创建AVD
  2. Android(安卓)Java调用ffmpeg命令
  3. android的消息机制
  4. android开发视频资源 电驴10G下载
  5. Android自适应屏幕大小和layout布局
  6. Android(安卓)ListView元素间隙线自定义
  7. Android读写XML(下)――创建XML文档
  8. 菜单 Android(安卓)Menu
  9. Simple Guide for Porting Android(安卓)
  10. android命令行下创建虚拟设备avd