diff --git a/main/src/main/java/com/yunbao/main/adapter/SearchResultsItemAdapter.java b/main/src/main/java/com/yunbao/main/adapter/SearchResultsItemAdapter.java index 5ada81ec5..222de46fc 100644 --- a/main/src/main/java/com/yunbao/main/adapter/SearchResultsItemAdapter.java +++ b/main/src/main/java/com/yunbao/main/adapter/SearchResultsItemAdapter.java @@ -22,6 +22,8 @@ public class SearchResultsItemAdapter extends RecyclerView.Adapter { private List> lists = new ArrayList<>(); private final int ANCHOR = 2, USER = 3; private int type = -1; + //确定是不是全部展示列表 + private boolean isAll = true; @NonNull @Override @@ -41,13 +43,13 @@ public class SearchResultsItemAdapter extends RecyclerView.Adapter { if (holder instanceof AnchorSearchResultsItemViewHolder) { AnchorSearchResultsItemViewHolder itemViewHolder = (AnchorSearchResultsItemViewHolder) holder; itemViewHolder.showAnchors(lists.get(position), ANCHOR); - if (type != 1) { + if (type != 1 && !isAll) { itemViewHolder.hideTypeTitle(); } } else { UserSearchResultsItemViewHolder viewHolder = (UserSearchResultsItemViewHolder) holder; viewHolder.showAnchors(lists.get(position), USER); - if (type != 1) { + if (type != 1 && !isAll) { viewHolder.hideTypeTitle(); } } @@ -60,7 +62,7 @@ public class SearchResultsItemAdapter extends RecyclerView.Adapter { @Override public int getItemViewType(int position) { - if (type == 1) { + if (type == 1 && lists.size() > 1) { if (position == (lists.size() - 1)) { return ANCHOR; } else { @@ -71,15 +73,31 @@ public class SearchResultsItemAdapter extends RecyclerView.Adapter { } /** - * 設置數據源 + * 設置數據源(处理数据源) * * @param mLists 數據源 * @param type */ public void showData(List> mLists, int type) { this.type = type; + //展示全部列表在只展示用户或者主播的一个判断,服务器在查全部的时候会返回两个集合没数据也会展示一个空集合 + if (mLists.size() > 1) { + isAll = true; + if (mLists.get(0).size() == 0) { + this.type = ANCHOR; + } + if (mLists.get(1).size() == 0) { + this.type = USER; + } + } else { + isAll = false; + } lists.clear(); - lists.addAll(mLists); + for (List searchModels : mLists) { + if (searchModels.size() > 0) { + lists.add(searchModels); + } + } notifyDataSetChanged(); } }