title: How to change Recycler Item Color?
body: <p><a href="https://i.stack.imgur.com/dSy21.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dSy21.jpg" alt="OUTPUT..."></a></p>
  
  <p>I have <code>RecyclerView</code> and I am inflating data. My requirement is that I have to show first item text in black color, the rest of the items should be in grey. And when user scroll then that grey color item should be black and its follower would be in grey again. I was thinking to this using position but I am confused.</p>
  
  <pre><code>    public class RecyclerViewAdapter extends RecyclerView.Adapter&lt;RecyclerViewAdapter.ViewHolder&gt;
      implements RecyclerViewFastScroller.BubbleTextGetter {
  
      private List&lt;String&gt; mDataArray;
  
      public RecyclerViewAdapter(List&lt;String&gt; dataset) {
          mDataArray = dataset;
      }
  
      @Override
      public int getItemCount() {
          if (mDataArray == null)
              return 0;
          return mDataArray.size();
      }
  
      @Override
      public RecyclerViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_recycler_view_layout, parent, false);
          ViewHolder vh = new ViewHolder(v);
          return vh;
      }
  
      @Override
      public void onBindViewHolder(ViewHolder holder, int position) {
          holder.mTextView.setText(mDataArray.get(position));
  
      }
  
      @Override
      public String getTextToShowInBubble(int pos) {
          if (pos &lt; 0 || pos &gt;= mDataArray.size())
              return null;
  
          String name = mDataArray.get(pos);
          if (name == null || name.length() &lt; 1)
              return null;
          return mDataArray.get(pos).substring(0, 1);
  
      }
  
      public static class ViewHolder extends RecyclerView.ViewHolder {
          @Bind(R.id.tv_alphabet)
          public TextView mTextView;
  
          public ViewHolder(View itemView) {
              super(itemView);
              ButterKnife.bind(this, itemView);
          }
      }
  
  }
  </code></pre>
  
  <p><strong>My updated code for onScrollIng and dynamic changing</strong></p>
  
  <pre><code>  @Override
  public void onBindViewHolder(MessageAdapter.ViewHolder holder, int position) {
  
      /*Tuesday, April 10, 2001 3:51 PM*/
  
      msgModels = msgList.get(position);
      if (msgList.get(position) != null) {
  
              holder.msgTitle.setText(msgModels.getMessageTitle());
              holder.msgDescription.setText(msgModels.getMessageDescription());
              holder.msgDate.setText(msgModels.getMessageDate());
      }
  
      if (position == firstVisible) {
          holder.msgTitle.setTextColor(Color.RED);
          holder.msgDescription.setTextColor(Color.RED);
          holder.msgDate.setTextColor(Color.RED);
      }else{
          holder.msgTitle.setTextColor(Color.BLUE);
          holder.msgDescription.setTextColor(Color.BLUE);
          holder.msgDate.setTextColor(Color.BLUE);
      }
  
  
  }
  
  @Override
  public int getItemCount() {
      return msgList.size();
  }
  
  private int firstVisible = 0;
  
  public void changeItem(int position){
      firstVisible = position;
      notifyItemChanged(firstVisible);
      notifyDataSetChanged();
  }
  
  
  public class ViewHolder extends RecyclerView.ViewHolder {
      public TextView msgTitle, msgDescription,msgDate;
  
      public ViewHolder(View view) {
          super(view);
          msgTitle  = (TextView)view.findViewById(R.id.msgTitle);
          msgDescription  = (TextView)view.findViewById(R.id.msgDescription);
          msgDate  = (TextView)view.findViewById(R.id.msgDate);
      }
  }
  }
  </code></pre>
  
  <p><strong>My Activity where I am calling Recycler onScroll</strong></p>
  
  <pre><code> private ProgressDialog mProgressDialog = null;
  private static final String API_MSG_CALL = "API_MSG_CALL";
  private Map&lt;String, String&gt; mapobject;
  private LinearLayoutManager linearLayoutManager;
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      View view = inflater.inflate(R.layout.fragment_message, null);
      mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_viewLaws);
      mRecyclerView.setAdapter(msgAdapter);
      mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
      msgAdapter = new MessageAdapter(msgList, getActivity(), this);
  
      linearLayoutManager = new LinearLayoutManager(getActivity());
  
      //msgAdapter.notifyDataSetChanged();
      mProgressDialog = new ProgressDialog(getActivity());
  
      mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
          @Override
          public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
              super.onScrolled(recyclerView, dx, dy);
              int firstVisible = linearLayoutManager.findFirstCompletelyVisibleItemPosition();
              msgAdapter.changeItem(firstVisible);
          }
      });
  </code></pre>