Problem
I have a list of items that are displayed in android through a FirebaseRecyclerAdapter. I create this adapter with a database reference on all the list of items (let's say "posts"). The post displays also the category and if the user click on the category, I would like to update the list to display only items on that category.
Solution I tried that doesn't work I put a click listener on the "category" textview and when the user click on it I tried to instantiate a new adapter with the new database query but it doesn't work.
Other ideas: Do it outside the adpater: create a new Intent to relaunch the fragment and create a new adapter with the new query
Question Did someone deal with the same situation where on a user click you want to filter the original list of items retrieved by the adpater? What is the best solution?
Details
protected void populateViewHolder(final PostViewHolder viewHolder, final Post post, final int position) {
/* Set the post text, author and category */
viewHolder.postText.setText(post.getText());
viewHolder.postAuthor.setText(post.getAuthor());
viewHolder.postCategory.setText(post.getCategory());
/* Set a listener on category so that
I refresh data with only that category */
viewHolder.quoteCategory.setOnClickListener(new View.OnClickListener() {
Post selectedPost = getItem(position);
@Override
public void onClick(View v) {
String category = selectedPost.getCategory();
// !!!! NOW I HAVE TO CHANGE DATA SET !!! ///
I think now I can create a new Fragment with a new adapter with correct Db reference... but is this the best way? Is there a way to use the same Adapater inside the populate view passing another query?