StudyTimeXrcAdapter.java 2.5 KB
package com.hh.xuetubao.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.hh.xuetubao.R;

import java.util.List;

public class StudyTimeXrcAdapter extends RecyclerView.Adapter<StudyTimeXrcAdapter.ViewHolder> {

    private Context context;
    private List<String> day;
    private List<String> time;

    public StudyTimeXrcAdapter(Context context, List<String> day, List<String> time) {
        this.context = context;
        this.day = day;
        this.time = time;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.rc_read_time, null);
        View viewById = view.findViewById(R.id.view_long);
        ViewGroup.LayoutParams params = viewById.getLayoutParams();
        int height = params.height;
        params.height = 1200;
        viewById.setLayoutParams(params);

        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        if (day.get(position) != null)
            holder.tvDay.setText(time.get(position));
        if (time.get(position) != null)
            holder.tvTime.setText(day.get(position));
        ViewGroup.LayoutParams params = holder.longView.getLayoutParams();
        Log.e("SSsss",day.get(position)+"");
        int a= Integer.valueOf(day.get(position).substring(day.get(position).length()-1,day.get(position).length()));
        Log.e("a_Position",a+"");
        params.height = a * 50;
        if(a == 0){
            holder.longView.setVisibility(View.GONE);
        }else {
            holder.longView.setLayoutParams(params);
        }
//        params.height = 100;

    }

    @Override
    public int getItemCount() {
        return day.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        private final TextView tvDay;
        private final TextView tvTime;
        private final View longView;

        public ViewHolder(View itemView) {
            super(itemView);
            tvDay = (TextView) itemView.findViewById(R.id.tv_day);
            tvTime = (TextView) itemView.findViewById(R.id.tv_time);
            longView = itemView.findViewById(R.id.view_long);
        }
    }
}