仿美团酒店时间选择
最近做项目有个需求是选择酒店入住和离店日期,准备着手写的时候没什么思路,去百度了一下就发现一两个博客,Github也很少,里面代码都差不多,刻下来运行一下,发现有bug,只好自己搞了,代码码思路结合网上的自己改改应该没问题;
思路在强大的recyclerview的item中嵌套recyclerview。
直接亮代码吧。
item中的item的布局R.layout.item_dateselect_day
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
android:id="@+id/linear_bg" xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:background="@color/color_white"
android:layout_height="75dp">
<TextView
android:id="@+id/tv_jr"
android:text=""
android:layout_gravity="center"
android:layout_marginBottom="12dp"
android:textSize="@dimen/text_size_12sp"
android:textColor="@color/color_text_b3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tv_day"
android:text=""
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:textSize="@dimen/text_size_17sp"
android:textColor="@color/color_text_b3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<View
android:background="@color/color_divider"
android:layout_width="match_parent"
android:layout_gravity="bottom"
android:layout_height="0.5dp"/>
</FrameLayout>
item中的item的adapter
package com.windmillsteward.jukutech.activity.home.commons.dataselect;
import android.content.Context;
import android.graphics.Color;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.windmillsteward.jukutech.R;
import java.util.List;
/**
* 描述:日
* 时间:2018/1/27/027
* 作者:xjh
*/
public class DayDateSelectAdapter extends RecyclerView.Adapter<DayDateSelectAdapter.Holder> {
private Context context;
private List<DayBean> list;
private onDateSelectListener listener;
public DayDateSelectAdapter(Context context, List<DayBean> list) {
this.context = context;
this.list = list;
}
public interface onDateSelectListener{
void onSelect(int pos);
}
public void setListener(onDateSelectListener listener) {
this.listener = listener;
}
@Override
public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.item_dateselect_day, parent, false);
return new Holder(view);
}
@Override
public void onBindViewHolder(final Holder holder, int position) {
DayBean entity = list.get(position);
if (entity.getDay()==0) {
holder.tv_day.setText("");
} else {
holder.tv_day.setText(entity.getDay()+"");
holder.tv_jr.setText(entity.getJr());
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (listener!=null) {
listener.onSelect(holder.getAdapterPosition());
}
}
});
if (entity.isSelect()) {
holder.itemView.setBackgroundColor(ContextCompat.getColor(context,R.color.color_them));
holder