MessageXrecAdapter.java 2.3 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.MsgListBean;

import java.util.List;

public class MessageXrecAdapter extends RecyclerView.Adapter<MessageXrecAdapter.ViewHolder> {
    private List<MsgListBean.MsgBean> mList;
    private Context context;

    public MessageXrecAdapter(List<MsgListBean.MsgBean> mList, Context context) {
        this.mList = mList;
        this.context = context;
    }

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

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, final int position) {
        MsgListBean.MsgBean bean = mList.get(position);
        if (bean.getTitle() != null)
            holder.title.setText(bean.getTitle());
        if (bean.getSendTime() != null)
            holder.time.setText(bean.getSendTime());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (turnToDetail != null)
                    turnToDetail.Turn(mList.get(position).getStatus(), mList.get(position).getMsgOid());
            }
        });
    }

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

    public class ViewHolder extends RecyclerView.ViewHolder {

        private final TextView title;
        private final TextView time;

        public ViewHolder(View itemView) {
            super(itemView);
            title = (TextView) itemView.findViewById(R.id.tv_title);
            time = (TextView) itemView.findViewById(R.id.tv_time);
        }
    }

    private TurnToDetail turnToDetail;

    public void setTurnToDetail(TurnToDetail turnToDetail) {
        this.turnToDetail = turnToDetail;
    }

    public interface TurnToDetail {
        void Turn(int Status, String MsgOid);
    }
}