PqAdapter.java 3.2 KB
package com.hh.xuetubao.adapter;

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

import com.hh.xuetubao.R;
import com.hh.xuetubao.bean.PQbean;

import java.util.List;

public class PqAdapter extends RecyclerView.Adapter<PqAdapter.ViewHolder> {
    private List<PQbean.RecordListBean> list;
    private Context context;

    public PqAdapter(List<PQbean.RecordListBean> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.xrv_pq, null);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.total.setText(String.valueOf(list.get(position).getTotalPQCoin()));
        if (list.get(position).getPaymentsType() != null) {
            holder.label.setText(list.get(position).getPaymentsType());
            if (list.get(position).getPaymentsType().equals("收入")) {
                holder.change.setText("+" + String.valueOf(list.get(position).getIncoming()));
                holder.label.setBackground(context.getResources().getDrawable(R.drawable.coners_green));
                holder.tvPq.setTextColor(context.getResources().getColor(R.color.color_008f44));
                holder.change.setTextColor(context.getResources().getColor(R.color.color_008f44));
            } else {
                holder.change.setText("-" + String.valueOf(list.get(position).getIncoming()));
                holder.label.setBackground(context.getResources().getDrawable(R.drawable.coners_orange));
                holder.tvPq.setTextColor(context.getResources().getColor(R.color.color_ff5400));
                holder.change.setTextColor(context.getResources().getColor(R.color.color_ff5400));
            }
        }

        if (list.get(position).getOperateName() != null)
            holder.reason.setText(list.get(position).getOperateName());
        if (list.get(position).getOperateTime() != null)
            holder.time.setText(list.get(position).getOperateTime());

    }

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

    public class ViewHolder extends RecyclerView.ViewHolder {

        private final TextView label;
        private final TextView total;
        private final TextView time;
        private final TextView change;
        private final TextView reason;
        private final TextView tvPq;

        public ViewHolder(View itemView) {
            super(itemView);
            label = (TextView) itemView.findViewById(R.id.label);
            reason = (TextView) itemView.findViewById(R.id.reason);
            change = (TextView) itemView.findViewById(R.id.change);
            time = (TextView) itemView.findViewById(R.id.time);
            total = (TextView) itemView.findViewById(R.id.total);
            tvPq = (TextView) itemView.findViewById(R.id.tv_pq);
        }
    }
}