SearchView超过1个recyclerview

时间:2018-02-17 13:57:54

标签: android android-recyclerview searchview

您好我有查看寻呼机 7个选项卡,其中所有内容都是 recyclerview 我想为所有这些添加搜索。 我试图将所有这些添加到一个回收站视图中进行搜索,但我真的不知道该怎么做。 任何人都可以给我一些提示,如何做到这一点? 我想在我的代码和单个回收站中添加一个搜索对话框查看我的所有项目这是可能的吗?  以及我的所有recyclerViews都有自己的适配器和分析器和模型,所有这些都彼此不同

以下是代码:

RecyclerView适配器类:

public class SearchAdapter extends RecyclerView.Adapter<SearchAdapter.SearchViewHolder> {


public SearchAdapter(Context context,int code) {
    this.code = code;
    this.context = context;
}
private Context context;
private int code;
private View view;
@Override
public SearchViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    switch (code){
        case 1:
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_item,parent,false);
            return new SearchViewHolder(view);
        case 2:
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.news_layout,parent,false);
            return new SearchViewHolder(view);
        case 3:
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.last_world_memes_list_item,parent,false);
            return new SearchViewHolder(view);
        case 4:
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.ex_list_tours_child,parent,false);
            return new SearchViewHolder(view);
        case 5:
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.last_url_view,parent,false);
            return new SearchViewHolder(view);
        case 6:
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.twitch,parent,false);
            return new SearchViewHolder(view);
    }
    return new SearchViewHolder(view);
}

@Override
public void onBindViewHolder(SearchViewHolder holder, int position) {
    switch (code){
        case 1:

    }
}

@Override
public int getItemCount() {
    return 0;
}

class SearchViewHolder extends RecyclerView.ViewHolder{
    //Events
    AppCompatTextView timeEvent ,tvPrizeEvent ,tvGameModeEvent ,tvBuyInEvent ,tvLateRegEvent
            ,tvSiteEvent ;
    AppCompatImageView ivEvent ;
    LinearLayout layoutEvent ;
    //Sites
    TextView tvSites;
    RelativeLayout headerImageSites;
    AppCompatImageView btnRevilSites;
    AppCompatTextView infoTvSites;
    AppCompatTextView infoDateSites;
    AppCompatButton btnUrlSites;
    AppCompatButton btnTelegramSites;
    AppCompatButton btnSupportSites;
    RelativeLayout layoutSites;
    AppCompatButton btnRegSites;
    LinearLayout layour_btnSites;
    RelativeLayout parentLayoutSites;
    //Tours
    RelativeLayout layoutTours ;
    SharedPreferences preferencesTours ;
    AppCompatTextView timeTourTours  ,tvPrizeTours  ,tvGameModeTours ,tvBuyInTours ,tvLateRegTours
            ,tvReBuyTours ,tvDaysTours;
    Clock clockTours ;
    //Memes
    AppCompatImageView ivMemes;
    AppCompatTextView tvIvMemes;
    AppCompatTextView tvDateIvMemes;
    public RelativeLayout layoutMemes;
    //News
    TextView tvNews;
    CardView btnNews;
    //Twitch
    AppCompatTextView viewrsTwitch ;
    AppCompatTextView languageTwitch;
    AppCompatTextView statusTwitch;
    CircleImageView profileTwitch;
    AppCompatImageView imageViewTwitch ;
    AppCompatTextView tvNameTwitch ;
    RelativeLayout urlLayoutTwitch ;
    SearchViewHolder(View itemView) {
        super(itemView);
        switch (code){
            case 1:
                timeEvent = (AppCompatTextView) itemView.findViewById(R.id.time_event);
                tvPrizeEvent = (AppCompatTextView) itemView.findViewById(R.id.event_prize);
                tvGameModeEvent = (AppCompatTextView) itemView.findViewById(R.id.event_gamemode);
                tvBuyInEvent = (AppCompatTextView) itemView.findViewById(R.id.event_buy_in);
                tvLateRegEvent = (AppCompatTextView) itemView.findViewById(R.id.event_late_reg);
                tvSiteEvent = (AppCompatTextView) itemView.findViewById(R.id.event_site);
                ivEvent = (AppCompatImageView) itemView.findViewById(R.id.iv_events);
                layoutEvent = (LinearLayout) itemView.findViewById(R.id.events_layout);
                return;
            case 2:
                tvNews = (TextView) itemView.findViewById(R.id.news_tv);
                btnNews = (CardView) itemView.findViewById(R.id.card_view_news);
                return;
            case 3:
                ivMemes = (AppCompatImageView) itemView.findViewById(R.id.last_world_news_iv);
                tvIvMemes = (AppCompatTextView) itemView.findViewById(R.id.last_world_news_iv_tv);
                tvDateIvMemes = (AppCompatTextView) itemView.findViewById(R.id.last_world_news_date_iv_tv);
                return;
            case 4:
                timeTourTours = (AppCompatTextView) itemView.findViewById(R.id.time_tour);
                tvPrizeTours = (AppCompatTextView) itemView.findViewById(R.id.tour_prize);
                tvGameModeTours = (AppCompatTextView) itemView.findViewById(R.id.tour_gamemode);
                tvBuyInTours = (AppCompatTextView) itemView.findViewById(R.id.tour_buy_in);
                tvLateRegTours = (AppCompatTextView) itemView.findViewById(R.id.tour_late_reg);
                tvReBuyTours = (AppCompatTextView) itemView.findViewById(R.id.tour_rebuy);
                tvDaysTours = (AppCompatTextView) itemView.findViewById(R.id.tour_days);
                clockTours = (Clock) itemView.findViewById(R.id.clock);
                return;
            case 5:
                tvSites = (TextView) itemView.findViewById(R.id.tv_sites);
                headerImageSites = (RelativeLayout) itemView.findViewById(R.id.last_url_cover_image);
                btnRevilSites = (AppCompatImageView) itemView.findViewById(R.id.btn_revil);
                infoTvSites = (AppCompatTextView) itemView.findViewById(R.id.info_tv);
                infoDateSites = (AppCompatTextView) itemView.findViewById(R.id.info_date);
                btnUrlSites = (AppCompatButton) itemView.findViewById(R.id.btn_url);
                btnTelegramSites = (AppCompatButton) itemView.findViewById(R.id.btn_telgram);
                btnSupportSites = (AppCompatButton) itemView.findViewById(R.id.btn_sup);
                layoutSites = (RelativeLayout) itemView.findViewById(R.id.revil);
                layour_btnSites = (LinearLayout) itemView.findViewById(R.id.layout_btn);
                btnRegSites = (AppCompatButton) itemView.findViewById(R.id.btn_reg);
                return;
            case 6:
                urlLayoutTwitch = (RelativeLayout) itemView.findViewById(R.id.url_layout);
                statusTwitch = (AppCompatTextView) itemView.findViewById(R.id.streamer_status);
                profileTwitch = (CircleImageView) itemView.findViewById(R.id.logo);
                imageViewTwitch = (AppCompatImageView) itemView.findViewById(R.id.twitch_icon);
                tvNameTwitch = (AppCompatTextView) itemView.findViewById(R.id.streamer_name);
        }
    }
}

1 个答案:

答案 0 :(得分:1)

在这里,您为所有不同的pojo使用了7个不同的RecyclerView课程。如果您想通过单个searchView进行搜索,则必须将所有pojo数据添加到单个pojo课程。但是,如果您将所有数据添加到单个pojo,则会在搜索时出现结果,但您很难找到该片段。

如果只想获得该viewPager片段的结果。然后,您必须为所有searchView类实现相同的pojo,并且您必须仅在fragment上获得结果。