zoukankan      html  css  js  c++  java
  • 冲刺第十二天

    UI:

    代码:

    SelectBarberDayAdapter.java

    package com.example.lileme.ThreeFragment.AppointmentButton;
    
    
    import android.content.Context;
    import android.graphics.Color;
    import android.support.v7.widget.RecyclerView;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.TextView;
    
    import com.example.lileme.R;
    
    import java.util.ArrayList;
    
    /**
     * Created by Administrator on 2016/7/16.
     */
    class SelectBarberDayAdapter extends RecyclerView.Adapter<SelectBarberDayAdapter.MyViewHolder> {
        private Context context;
        private ArrayList<RecyclerData> list;
    
        private int defItem = -1;
        private OnItemListener onItemListener;
    
        public SelectBarberDayAdapter(Context context, ArrayList<RecyclerData> list) {
            this.context=context;
            this.list=list;
        }
        public void setOnItemListener(OnItemListener onItemListener) {
            this.onItemListener = onItemListener;
        }
        public interface OnItemListener {
            void onClick(MyViewHolder holder, int position);
        }
        public void setDefSelect(int position) {
            this.defItem = position;
        }
    
    
        @Override
        public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            MyViewHolder holder = new MyViewHolder(LayoutInflater.from(
                    context).inflate(R.layout.layout_select_barber_day, parent,
                    false));
            return holder;
        }
    
        @Override
        public void onBindViewHolder(final MyViewHolder holder, final int position) {
            holder.tv.setText(list.get(position).content);
            RecyclerData re=list.get(position);
            if(position == 0){
                holder.tv.setSelected(true);
                holder.tv.setTextColor(Color.parseColor("#ffffff"));
                holder.tv.setBackgroundResource(R.drawable.btn_day_hour_select);
            }
            if (defItem != -1) {
                if (defItem == position) {
    //              点击的位置
                    if(re.isSelect==true){
                        //              选中状态
                        holder.tv.setTextColor(Color.parseColor("#ffffff"));
                        holder.tv.setBackgroundResource(R.drawable.btn_day_hour_select);
                    }else {
                        holder.tv.setTextColor(Color.parseColor("#000000"));
                        holder.tv.setBackgroundResource(R.drawable.btn_day_hour_unselect);
                    }
    
                } else {
    //              没有点击的位置都变成默认背景
                    holder.tv.setTextColor(Color.parseColor("#000000"));
                    holder.tv.setBackgroundResource(R.drawable.btn_day_hour_unselect);
                    list.get(position).isSelect=false;
                }
            }
            holder.tv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (onItemListener != null) {
                        onItemListener.onClick(holder, position);
                    }
                }
            });
        }
    
        @Override
        public int getItemCount() {
            return list.size();
        }
    
        /**
         * ViewHolder的类,用于缓存控件
         */
        class MyViewHolder extends RecyclerView.ViewHolder {
            TextView tv;
            public MyViewHolder(View view) {
                super(view);
                tv = view.findViewById(R.id.tv_day);
            }
        }
    }

    layout_select_barber_day.xml

     1 <?xml version="1.0" encoding="utf-8"?>
     2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     3     android:layout_width="90dp"
     4     android:layout_height="wrap_content"
     5     android:orientation="vertical">
     6 
     7     <TextView
     8         android:id="@+id/tv_day"
     9         android:layout_width="match_parent"
    10         android:layout_height="80dp"
    11         android:gravity="center"
    12         android:text="周二06-10"
    13         android:textSize="16dp"
    14         android:background="@drawable/btn_day_hour_unselect"
    15         />
    16 </LinearLayout>
  • 相关阅读:
    多线程ExecutorService 的理解与使用
    MySql索引
    HttpURLConnection和HttpClient使用
    httpclient调用接口
    几个linux命令
    面试之自定义字符串操作
    C和C++中struct的区别
    如何根据端口号查看占用进程
    linux和window如何发布服务
    MYSQL中GROUP_CONCAT和CONCAT函数配合使用
  • 原文地址:https://www.cnblogs.com/zhangzhongkun/p/11060878.html
Copyright © 2011-2022 走看看