布局样式
<LinearLayout
android:id="@+id/select_day_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:id="@+id/start_day_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="4月14日"
android:textColor="#242424"
android:textSize="18sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="入店"
android:textColor="#242424"
android:textSize="12sp" />
</LinearLayout>
<TextView
android:layout_width="21dp"
android:layout_height="1dp"
android:layout_marginLeft="@dimen/dp_12"
android:layout_marginRight="@dimen/dp_12"
android:background="#242424" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/end_day_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="4月15日"
android:textColor="#242424"
android:textSize="18sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="离店"
android:textColor="#242424"
android:textSize="12sp" />
</LinearLayout>
<TextView
android:id="@+id/total_day_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:drawablePadding="@dimen/dp_4"
android:gravity="center"
android:text="共1晚"
android:drawableRight="@mipmap/hoteljump"
android:textColor="#242424"
android:textSize="13sp" />
</LinearLayout>
Activity调用
/**
* 日历选择器
*/
private int startGroup = -1;
private int endGroup = -1;
private int startChild = -1;
private int endChild = -1;
private DatePopupWindow datePopupWindow;//入住酒店的日历选择器
private void showDatePopupWindow() {
if (null == datePopupWindow) {
datePopupWindow = new DatePopupWindow.Builder(mActivity, Calendar.getInstance().getTime(), mRootView)//初始化
.setInitSelect(startGroup, startChild, endGroup, endChild)//设置上一次选中的区间状态
.setInitDay(false)//默认为true,UI内容为共几天、开始、结束;当为false时,UI内容为共几晚、入住、离开
.setDateOnClickListener(new DatePopupWindow.DateOnClickListener() {//设置监听
//点击完成按钮后回调返回方法
@Override
public void getDate(String startDate, String endDate, int startGroupPosition, int
startChildPosition, int endGroupPosition, int endChildPosition) {
startGroup = startGroupPosition;//开始月份位置
startChild = startChildPosition;//开始对应月份中日的位置
endGroup = endGroupPosition;//结束月份位置
endChild = endChildPosition;//结束对应月份中日的位置
String mStartTime = DateUtils.FormatDateMD(startDate);
String mEndTime = DateUtils.FormatDateMD(endDate);
startDayTv.setText(mStartTime);
endDayTv.setText(mEndTime);
//需要格式化日期 转成接口需要的日期格式
checkInDate = DateUtils.formatDate(startDate);
checkOutDate = DateUtils.formatDate(endDate);
totalDay = Integer.parseInt(CalendarUtil.getTwoDay(endDate, startDate));
totalDayTv.setText(totalDay + "晚");
page = 1;
initMap();
mPresenter.getNewHotelList(true, map, lat, lng);
}
}).builder();
} else {
datePopupWindow.showAsDropDown(selectDayLayout);
}
}