Android 기본 어댑터 아래쪽 및 헤드 레이아웃 추가
getItemViewType ,getItemCount,onCreateViewHolder (getItemCount size+1 )
@Override
public int getItemViewType(int position) { position
if (position == resultData.size()) {
return FOOTER_TYPE;
} else {
return ITEM_TYPE;
}
}
@Override
public int getItemCount() {
return resultData.size() > 0 ? resultData.size() + 1 : 0;
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
if (viewType == FOOTER_TYPE) {
return new ScrollViewHolder(inflater.inflate(R.layout.item_scroll_layout2, parent, false));
} else {
return new FooterViewHolder(inflater.inflate(R.layout.comment_footer, parent, false));
}
}
package com.guwu.varysandroid.ui.data.adapter;
import android.content.Context;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.RequiresApi;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.guwu.varysandroid.R;
import com.guwu.varysandroid.bean.GetInformationAccountBean;
import com.guwu.varysandroid.utils.SynScrollerLayout;
import java.util.List;
public class DataAnalysisAdapter extends RecyclerView.Adapter {
private Context mContext;
private SynScrollerLayout mSynScrollerview;
private String constType;
private final int FOOTER_TYPE = 1;
private final int ITEM_TYPE = 2;
private final int TOP_TYPE = 3;
private LayoutInflater inflater;
private List resultData;
public DataAnalysisAdapter(Context context, List resultData, SynScrollerLayout mSynScrollerview, String type) {
this.mContext = context;
this.mSynScrollerview = mSynScrollerview;
this.constType = type;
this.resultData = resultData;
this.inflater = LayoutInflater.from(context);
}
public void setNewData(List resultData) {
this.resultData = resultData;
notifyDataSetChanged();
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
if (viewType == FOOTER_TYPE) {
return new ScrollViewHolder(inflater.inflate(R.layout.item_scroll_layout2, parent, false));
} else {
return new FooterViewHolder(inflater.inflate(R.layout.comment_footer, parent, false));
}
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
if (holder instanceof ScrollViewHolder) {
ScrollViewHolder itemHolder = (ScrollViewHolder) holder;
if (resultData.size() > 0) {
itemHolder.mView.setText(String.valueOf(resultData.get(position).getDate()));
if (TextUtils.equals("user_type", constType)) {
itemHolder.tvPlatform.setText(resultData.get(position).getPlatName());
itemHolder.tv_fans.setText(String.valueOf(resultData.get(position).getFansTotalCnt()));
itemHolder.tv_fans_num.setText(String.valueOf(resultData.get(position).getFansCnt()));
itemHolder.tv_video.setText("");
} else if (TextUtils.equals("platform_type", constType)) {
itemHolder.tvPlatform.setText(resultData.get(position).getPlatName());
itemHolder.tv_fans.setText(String.valueOf(resultData.get(position).getArticleCnt()));
itemHolder.tv_fans_num.setText(String.valueOf(resultData.get(position).getArticleCnt()));
itemHolder.tv_video.setText(String.valueOf(resultData.get(position).getVideoCnt()));
itemHolder.tv_read.setText(String.valueOf(resultData.get(position).getReadCnt()));
itemHolder.tv_play.setText(String.valueOf(resultData.get(position).getPlayCnt()));
itemHolder.tv_like.setText(String.valueOf(resultData.get(position).getLikeCnt()));
itemHolder.tv_share.setText(String.valueOf(resultData.get(position).getShareCnt()));
itemHolder.tv_collect.setText(String.valueOf(resultData.get(position).getCollectCnt()));
itemHolder.tv_comments.setText(String.valueOf(resultData.get(position).getCommentCnt()));
itemHolder.tv_recommend.setText(String.valueOf(resultData.get(position).getRecommendCnt()));
}
if (position % 2 == 0) {
itemHolder.ll_layout_item.setBackground(mContext.getDrawable(R.drawable.user_analyze_top));
} else {
itemHolder.ll_layout_item.setBackground(mContext.getDrawable(R.drawable.user_analyze_top_while));
}
mSynScrollerview.setOnScrollListener((l, t, oldl, oldt) -> itemHolder.mSynScrollerLayout.smoothScrollTo(l, 0));// RecyclerView
}
} else if (holder instanceof FooterViewHolder) {
FooterViewHolder footerHolder = (FooterViewHolder) holder;
footerHolder.mTVFooter.setText(" ");
}
}
@Override
public int getItemCount() {
return resultData.size() > 0 ? resultData.size() + 1 : 0;
}
@Override
public int getItemViewType(int position) { // position
if (position == resultData.size()) {
return FOOTER_TYPE;
}else if(position == 0){
return TOP_TYPE;
} else {
return ITEM_TYPE;
}
}
private class ScrollViewHolder extends RecyclerView.ViewHolder {
private TextView mView;
private SynScrollerLayout mSynScrollerLayout;
private LinearLayout mChildRoot, ll_layout_item;
private TextView tv_fans;
private TextView tvPlatform;
private TextView tv_fans_num;
private TextView tv_video;
private TextView tv_read;
private TextView tv_play;
private TextView tv_like;
private TextView tv_share;
private TextView tv_collect;
private TextView tv_comments;
private TextView tv_recommend;
private ScrollViewHolder(@NonNull View itemView) {
super(itemView);
mView = itemView.findViewById(R.id.tv);
mSynScrollerLayout = itemView.findViewById(R.id.syn_scroller);
ll_layout_item = itemView.findViewById(R.id.ll_layout_item);
mChildRoot = itemView.findViewById(R.id.ll_child_root);
tv_fans = itemView.findViewById(R.id.tv_fans);
tvPlatform = itemView.findViewById(R.id.tv_platform);
tv_fans_num = itemView.findViewById(R.id.tv_fans_num);
tv_video = itemView.findViewById(R.id.tv_video);
tv_read = itemView.findViewById(R.id.tv_read);
tv_play = itemView.findViewById(R.id.tv_play);
tv_like = itemView.findViewById(R.id.tv_like);
tv_share = itemView.findViewById(R.id.tv_share);
tv_collect = itemView.findViewById(R.id.tv_collect);
tv_comments = itemView.findViewById(R.id.tv_comments);
tv_recommend = itemView.findViewById(R.id.tv_recommend);
}
}
public class FooterViewHolder extends RecyclerView.ViewHolder {
RelativeLayout mRLFooter;
TextView mTVFooter;
FooterViewHolder(View itemView) {
super(itemView);
mRLFooter = itemView.findViewById(R.id.rl_footer);
mTVFooter = itemView.findViewById(R.id.tv_footer);
}
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.