0

I'm using section luizgrp sectionedrecyclerviewadapter with sections and headers , and on item select i change the text color then notifyData but it reflects only in one section , every section has a selected item colored , how can i notify the whole list?

 @Override
public void onBindItemViewHolder(RecyclerView.ViewHolder holder, final int position) {
    final ItemViewHolder itemHolder = (ItemViewHolder) holder;
    if(position == selectedPosition) {
        itemHolder.txtTime.setTextColor(Color.parseColor("#00aaff"));
        itemHolder.txtType.setTextColor(Color.parseColor("#00aaff"));
    } else {
        itemHolder.txtTime.setTextColor(Color.parseColor("#000000")); 
        itemHolder.txtType.setTextColor(Color.parseColor("#000000"));
    }


        itemHolder.rootView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                selectedPosition=position;
                recyclerView.getAdapter().notifyDataSetChanged();
            }
        });
    }


}
Gustavo Pagani
  • 6,583
  • 5
  • 40
  • 71
  • add only notifyDataSetChanged() instead of recyclerView.getAdapter().notifyDataSetChanged(); – Sharath kumar Sep 21 '17 at 10:22
  • can you show me your activity code also where you are setting adapter? – Sunil Sep 21 '17 at 10:22
  • try it by setting the color in `onCreateViewHolder()` so that each time when your row is created it will set the color – Stuti Kasliwal Sep 21 '17 at 10:24
  • @Anonymous can't resolve notifyDataSetChanged() only – Amira Rabie Sep 21 '17 at 10:25
  • what?your extending recycler adapter only no?post your whole code,if it is adapter then thtat method should be onBindViewHolder but yours it is onBindItemViewHolder – Sharath kumar Sep 21 '17 at 10:27
  • i'm using https://github.com/luizgrp/SectionedRecyclerViewAdapter so the code is written in class MySection extends StatelessSection not adapter – Amira Rabie Sep 21 '17 at 10:34
  • If the user clicks on item #1 of section #1, do you want to ONLY change the color of item #1 of section #1 or you want to change the color of ALL items #1 of all sections? – Gustavo Pagani Oct 31 '17 at 12:02
  • In the onClick event you are storing the position of item #1 in section #1, not in the whole adapter, if you want the color to be changed only in one section you should use the value from [holder.getAdapterPosition()](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.ViewHolder.html#getAdapterPosition()) to store in selectedPosition – Gustavo Pagani Oct 31 '17 at 12:08
  • and use the value from [getPositionInSection](https://github.com/luizgrp/SectionedRecyclerViewAdapter/blob/918337f66321055c7621377e5f5254b9b8078e4c/library/src/main/java/io/github/luizgrp/sectionedrecyclerviewadapter/SectionedRecyclerViewAdapter.java#L376) when comparing with position – Gustavo Pagani Oct 31 '17 at 12:08
  • Hi @Amira Rabie i would like to ask how did you solved this? I got the same issue.. Thankyou :) – Aiiz Cabuhat Ü May 19 '19 at 17:00

0 Answers0