0

Actually, I make a 1st query which returns a number of objects.

As we could with a standard recyclerView, I would like to filter dynamically these objects with an EditText after the view is created, and update the view dynamically.

For example, if my first query returns and displays 10 objects, the user will be able to search one objet through the 10 objects by making a request with an EditText. The view will display only this object.

Query query = collectionRef.whereArrayContains("customerNearMe", getCurrentUser().getUid());

private void sendToAdapter(Query query) {

        FirestoreRecyclerOptions<Restaurant> options = new FirestoreRecyclerOptions.Builder<Restaurant>()
                .setQuery(query, Restaurant.class)
                .build();

        adapter = new RestaurantAdapter(options);
        recyclerView.setHasFixedSize(true);

        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        recyclerView.setAdapter(adapter);

        DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(), DividerItemDecoration.VERTICAL);
        recyclerView.addItemDecoration(new SimpleItemDecorator(getContext()));
        adapter.notifyDataSetChanged();

    }

    @Override
    public void onStart() {
        super.onStart();
        adapter.startListening();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        adapter.stopListening();
    }

Actually, I know how to do it with a simple RecyclerView


    private void filter(String text) {
        ArrayList<ExampleItem> filteredList = new ArrayList<>();

        for (ExampleItem item : mExampleList) {
            if (item.getText1().toLowerCase().contains(text.toLowerCase())) {
                filteredList.add(item);
            }
        }

        mAdapter.filterList(filteredList);
    }

but I am a newbie with Firestore.

Alek KT
  • 134
  • 1
  • 1
  • 9

0 Answers0