0

I'm using the Firebase RecyclerAdapter to display a list of things. How do I change the colour of all the items in the RecyclerView except the selected item back to a different colour? Changing the colour of the selected item is straightforward.

 FirebaseRecyclerAdapter<Home_List, SubChatHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Home_List, SubChatHolder>(

                Home_List.class,
                R.layout.single_division_layout,
                SubChatHolder.class,
                ref

        ) {
            @Override
            protected void populateViewHolder(final SubChatHolder viewHolder, final Home_List model, int position) {

                final String id = getRef(position).getKey();

                viewHolder.setName(model.getName());

                viewHolder.mView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                       mView.viewHolder.setSelectedBg();
                       //how to uncolour the previously selected item?
                    }
                });
            }
        };
Arjun Ram
  • 369
  • 2
  • 18

1 Answers1

1

How are you selecting the position? By clicking on the item?

If that's the case, you don't event need the position. All you need to do is to change the (background) color of mView in your onClick method, where your change the color of selected item comment is.

Your problem here is going to be deselection of the item, as it is going to remain colored otherwise. You are going to have to find all the views inside the RecyclerView and reset the background color.

EDIT

Here is the link from comments with one of possible solutions: https://stackoverflow.com/a/40712773/6835732

Primož Ivančič
  • 1,984
  • 1
  • 17
  • 29