如何使用Firebase RecycleView添加搜索字段

时间:2018-02-24 19:25:33

标签: android firebase firebase-realtime-database firebaseui

PLZ帮助我解决我的问题,我想添加搜索栏

帮助我解决我的问题我想添加搜索栏当我在编辑文本中添加内容时会过滤RecycleView。仅显示我正在使用FirebaseRecycleAdapter用户搜索的内容,并且不知道如何使用此适配器过滤内容。

protected void onStart() {
super.onStart();
   FirebaseRecyclerAdapter<Blog, BlogViewHolder> firebaseRecycleAdapter= 
   new FirebaseRecyclerAdapter<Blog, BlogViewHolder>(

        # here i am using blog class for get just content from firebase
         Blog.class,
         R.layout.blog_list,
         BlogViewHolder.class,
         # mdatabase is FirebaseRefrence.
            mdatabase
     ) {
        @Override
        protected void populateViewHolder(final BlogViewHolder viewHolder, 
          final Blog model, int position) {
            viewHolder.setBranchname(model.getBranchname());
            viewHolder.setResultlink(model.getResultlink());

          final String searchContent = searchbar.getText().toString();
            searchbar.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int 
                count, int after) {
                }

                @Override
                public void onTextChanged(CharSequence s, int start, int 
              before, int count) {
        #something write there i donot know what to right 
                }
                 @Override
                public void afterTextChanged(Editable s) {

                }
            });
        }
    };

# Linear Layout Manager is used to set Content in particular order and 
#   this help to set update post visible on first position


    final LinearLayoutManager mLinearLayoutManager = new 
    LinearLayoutManager(this);
    mLinearLayoutManager.canScrollVertically();
    mLinearLayoutManager.setReverseLayout(true);
    mLinearLayoutManager.setStackFromEnd(true);
    mbloglist.setLayoutManager(mLinearLayoutManager);
    firebaseRecycleAdapter.registerAdapterDataObserver(new 
      RecyclerView.AdapterDataObserver() {
        @Override
        public void onItemRangeInserted(int positionStart, int itemCount) {
            super.onItemRangeInserted(positionStart, itemCount);
           // int friendlyMessageCount = 
    firebaseRecyclerAdapter.getItemCount();
            // If the recycler view is initially being loaded or the
            // user is at the bottom of the list, scroll to the bottom
            // of the list to show the newly added message.\
            mLinearLayoutManager.scrollToPosition(positionStart);
        }
      });
      mbloglist.setAdapter(firebaseRecycleAdapter);
      }

1 个答案:

答案 0 :(得分:1)

尝试阅读官方文档。方法startAt ()endAt()limitToFirst ()limitToLast ()orderByChild()会对您有所帮助。链接:https://firebase.google.com/docs/database/android/lists-of-data