我想在回收站 View 的底部添加页脚布局。下面是我的适配器 View ,它可以扩大页眉布局以及其他项目。感谢帮助!
public class SplitMembersAdapter extends RecyclerViewAdapter<SplitMember, SplitMemberViewHolder> {
private final ArrayList<SplitMember> mSplitMembersList;
private final ImageLoader mImageLoader;
private static final int TYPE_HEADER = 0;
private static final int TYPE_ITEM = 1;
private int splitAmount;
private boolean isAmountSplitted;
public SplitMembersAdapter(ArrayList<SplitMember> members,ImageLoader imageLoader) {
mSplitMembersList = members;
mImageLoader = imageLoader;
}
@Override
public int getItemCount() {
return mSplitMembersList.size();
}
@Override
public int getItemViewType(int position) {
if (isPositionHeader(position)) {
return TYPE_HEADER;
}
return TYPE_ITEM;
}
private static boolean isPositionHeader(int position) {
return position == 0;
}
@Override
public SplitMemberViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
View itemView = LayoutInflater.from(viewGroup.getContext()).
inflate(R.layout.split_member_item_layout, viewGroup, false);
return new SplitMemberViewHolder(itemView);
}
@Override
public void onBindViewHolder(SplitMemberViewHolder viewHolder, int position) {
SplitMember contact = mSplitMembersList.get(position);
viewHolder.splitMemAmount.setText(String.format("%.2f", contact.getShare()));
viewHolder.splitMemberColor.setBackgroundColor(contact.getColor());
if (position == TYPE_HEADER){
viewHolder.splitMemName.setText("You");
mImageLoader.loadImage(contact.getImg(),
viewHolder.splitMemImg, R.drawable.empty_user_placeholder);
}
else {
viewHolder.splitMemName.setText(contact.getName());
mImageLoader.loadImage(Utils.getProfileImageUrl(contact.getImg()),
viewHolder.splitMemImg,R.drawable.empty_user_placeholder);
}
}
}
class SplitMemberViewHolder extends RecyclerView.ViewHolder {
public BezelImageView splitMemImg;
public TextView splitMemName;
public TextView splitMemAmount;
public View splitMemberColor;
public SplitMemberViewHolder(View itemView) {
super(itemView);
splitMemberColor = itemView.findViewById(R.id.member_color);
splitMemImg = (BezelImageView) itemView.findViewById(R.id.member_profile_image);
splitMemName = (TextView) itemView.findViewById(R.id.member_name);
splitMemAmount = (TextView) itemView.findViewById(R.id.member_amount);
}
}
最佳答案
与添加页眉类似,也添加页脚。
public class SplitMembersAdapter extends RecyclerViewAdapter<SplitMember, SplitMemberViewHolder> {
private final ArrayList<SplitMember> mSplitMembersList;
private final ImageLoader mImageLoader;
private static final int TYPE_HEADER = 0;
private static final int TYPE_ITEM = 1;
private static final int TYPE_FOOTER = 2;
private int splitAmount;
private boolean isAmountSplitted;
public SplitMembersAdapter(ArrayList<SplitMember> members,ImageLoader imageLoader) {
mSplitMembersList = members;
mImageLoader = imageLoader;
}
@Override
public int getItemCount() {
return mSplitMembersList.size();
}
@Override
public int getItemViewType(int position) {
if (isPositionHeader(position)) {
return TYPE_HEADER;
}ELSE if (isPositionFooter(position)) {
return TYPE_Footer;
}
return TYPE_ITEM;
}
private static boolean isPositionHeader(int position) {
return position == 0;
}
private static boolean isPositionFooter(int position) {
return position == mSplitMembersList.size()-1;
}
@Override
public SplitMemberViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
switch(viewType){
case TYPE_HEADER:
//return header view holder;
break;
case TYPE_ITEM:
//return item view holder;
break;
case TYPE_FOOTER:
//return footer view holder;
break;
}
}
@Override
public void onBindViewHolder(SplitMemberViewHolder viewHolder, int position) {
switch(getItemViewType(position)){
case TYPE_HEADER:
//bind header data;
break;
case TYPE_ITEM:
//bind item data
break;
case TYPE_FOOTER:
//bind footer data.
break;
}
}
}
class SplitMemberViewHolder extends RecyclerView.ViewHolder {
public BezelImageView splitMemImg;
public TextView splitMemName;
public TextView splitMemAmount;
public View splitMemberColor;
public SplitMemberViewHolder(View itemView) {
super(itemView);
splitMemberColor = itemView.findViewById(R.id.member_color);
splitMemImg = (BezelImageView) itemView.findViewById(R.id.member_profile_image);
splitMemName = (TextView) itemView.findViewById(R.id.member_name);
splitMemAmount = (TextView) itemView.findViewById(R.id.member_amount);
}
}