上划加载更多

public class SystemInfoAdapter extends RecyclerView.Adapter {

    //1、创建三种布局的TYPE值,1、2、3
    //2、创建三个ViewHolder
    //3、增加新的方法  getItemViewType()
    //4、在onCreateViewHolder 中选择布局填充页面
    //5、在onBindViewHolder 中填充数据
    public Context mContext;
    public LayoutInflater inflater;
    public List mList;
    public final int TYPE_TITLE=1;
    public final int TYPE_CONTENT_TEXT=2;
    public final int TYPE_CONTENT_BTN=3;

    public class SysteminfoModel{
        private String title_str;
        private int type;

        public String getTitle_str() {
            return title_str;
        }

        public void setTitle_str(String title_str) {
            this.title_str = title_str;
        }

        public int getType() {
            return type;
        }

        public void setType(int type) {
            this.type = type;
        }
    }

    public class TitleViewHolder extends RecyclerView.ViewHolder{

        private TextView tv_title;
        public TitleViewHolder(View itemView) {
            super(itemView);
            tv_title= (TextView) itemView.findViewById(R.id.tv_title);
        }
    }
    public class ContentTextViewHolder extends RecyclerView.ViewHolder{

        private TextView tv_key;
        private TextView tv_value;

        public ContentTextViewHolder(View itemView) {
            super(itemView);
            tv_key=itemView.findViewById(R.id.tv_key);
            tv_value=itemView.findViewById(R.id.tv_value);
        }
    }
    public class ContentBtnViewHolder extends RecyclerView.ViewHolder{

        private TextView tv_key;
        private Button btn_str;
        public ContentBtnViewHolder(View itemView) {
            super(itemView);
            tv_key=itemView.findViewById(R.id.tv_key);
            btn_str=itemView.findViewById(R.id.btn_str);
        }
    }

    @Override
    public int getItemViewType(int position) {
        int type=mList.get(position).getType();
        return type;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if(viewType==TYPE_TITLE){
            return new TitleViewHolder(inflater.inflate(R.layout.layout_title_item,null));
        }else if(viewType==TYPE_CONTENT_TEXT){
            return new ContentTextViewHolder(inflater.inflate(R.layout.layout_content_text_item,null));
        }else if(viewType==TYPE_CONTENT_BTN){
            return new ContentBtnViewHolder(inflater.inflate(R.layout.layout_content_btn_item,null));
        }
        return null;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        SysteminfoModel syseminfoModel = mList.get(position);
        if (holder instanceof TitleViewHolder){
            ((TitleViewHolder) holder).tv_title.setText(syseminfoModel.title_str);
        }else if (holder instanceof ContentTextViewHolder){
            ((ContentTextViewHolder) holder).tv_key.setText(syseminfoModel.title_str);
            ((ContentTextViewHolder) holder).tv_value.setText(syseminfoModel.title_str);
        }else if(holder instanceof ContentBtnViewHolder){
            ((ContentBtnViewHolder) holder).tv_key.setText(syseminfoModel.title_str);
            ((ContentBtnViewHolder) holder).btn_str.setText(syseminfoModel.title_str);
        }
    }

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

你可能感兴趣的:(Util类,Android知识)