0

plz help me solve my problem i want to add search bar

help me solve my problem i want to add search bar when i put something in edit text it will filter the RecycleView. show only that content which user search i am using FirebaseRecycleAdapter and don't know how to filter the content with this adapter.

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);
      }
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807

1 Answers1

1

Try to read the official documentation. The methods startAt (), endAt(), limitToFirst (), limitToLast (), orderByChild() will help you. Link: https://firebase.google.com/docs/database/android/lists-of-data