title: Recyclerview change item color outside adapter
body: <p>Currently I'm trying figure out how to change an <code>RecyclerView</code> item color outside adapter. I'm just manipulating the position, and works fine! But I must swipe the page to color update, and I don't know what I should do to fix this problem.</p>
  
  <p>Check my code:</p>
  
  <p><strong>MainActivity.java</strong></p>
  
  <pre><code>...
  protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          ...
  
  
          adapter = new viewPagerAdapter(getSupportFragmentManager());
  
          //Add fragments here
          adapter.addFragment(new fragmentList(), ""); //Lista de música
          adapter.addFragment(new fragmentFrequent(), ""); //Frequentes
          adapter.addFragment(new fragmentPlayList(), ""); //Playlist
  
          viewPager.setAdapter(adapter);
          tabLayout.setupWithViewPager(viewPager);
  
          player_prev = findViewById(R.id.prev);
          player_prev.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  if ((currentPos-1) &gt; 0) {
                      killMediaPlayer();
                      initAudio(getApplicationContext(), 
                      RecyclerViewAdapter.mData.get(currentPos - 1).getURL());
                      currentPos -= 1;
  
  
                      RecyclerViewAdapter.OldselectedPos = RecyclerViewAdapter.selectedPos;
                      RecyclerViewAdapter.selectedPos = currentPos;
                      adapter.notifyDataSetChanged();
              }
          });
  
          ...
  }
  </code></pre>
  
  <p><strong>RecyclerViewAdapter.java</strong></p>
  
  <pre><code>package etes.xdda.music;
  import android.app.Dialog;
  import android.graphics.Color;
  import android.graphics.drawable.ColorDrawable;
  import android.support.v4.content.ContextCompat;
  import android.support.v7.widget.RecyclerView;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ImageButton;
  import android.widget.ImageView;
  import android.widget.LinearLayout;
  import android.widget.TextView;
  import android.widget.Toast;
  
  import java.util.List;
  
  
  public class RecyclerViewAdapter extends RecyclerView.Adapter&lt;RecyclerViewAdapter.MyViewHolder&gt; implements View.OnClickListener{
  
  
      MainActivity activity;
      static List&lt;mList&gt; mData;
      Dialog myDialog;
  
      public static int selectedPos = RecyclerView.NO_POSITION;
      public static int OldselectedPos = RecyclerView.NO_POSITION;
  
      private LinearLayout menu_dialog, menu_dialog2;
      public static TextView song_detail;
      public RecyclerViewAdapter(MainActivity activity, List&lt;mList&gt; mData) {
          this.activity = activity;
          this.mData = mData;
      }
  
      @Override
      public void onClick(View view) { }
  
      @Override
      public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          View v;
          v = LayoutInflater.from(activity).inflate(R.layout.item_list, parent, false);
          final MyViewHolder vHolder = new MyViewHolder(v);
  
          // Dialog ini
          myDialog = new Dialog(activity);
          myDialog.setContentView(R.layout.dialog);
          myDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
  
          vHolder.item_play.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v)
              {
                  TextView dialog_name_tv = myDialog.findViewById(R.id.dialog_name_id);
                  TextView dialog_phone_tv = myDialog.findViewById(R.id.dialog_author_id);
                  ImageView dialog_contact_img = myDialog.findViewById(R.id.dialog_img);
                  dialog_name_tv.setText(mData.get(vHolder.getAdapterPosition()).getName());
                  dialog_phone_tv.setText(mData.get(vHolder.getAdapterPosition()).getPhone());
                  dialog_contact_img.setImageResource(mData.get(vHolder.getAdapterPosition()).getPhoto());
  
                  //Toast.makeText(mContext, "Test click "+String.valueOf(vHolder.getAdapterPosition()), Toast.LENGTH_SHORT).show();
                  myDialog.show();
              }
          });
          vHolder.menu_play.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v)
              {
                  OldselectedPos = selectedPos;
                  selectedPos = vHolder.getAdapterPosition();
  
                  notifyItemChanged(selectedPos);
                  notifyItemChanged(OldselectedPos);
  
  
                  menu_dialog = v.getRootView().findViewById(R.id.menu_dialog);
                  menu_dialog.setVisibility(v.VISIBLE);
  
                  menu_dialog2 = v.getRootView().findViewById(R.id.menu_dialog2);
                  menu_dialog2.setVisibility(v.VISIBLE);
  
                  song_detail = v.getRootView().findViewById(R.id.song_detail);
                  song_detail.setVisibility(v.VISIBLE);
  
  
                  String newName;
                  newName = mData.get(vHolder.getAdapterPosition()).getName();
                  if (newName.length() &gt; 42) {
                      newName = newName.substring(0, 38) + "...";
                  }
                  song_detail.setText(newName);
  
                  activity.killMediaPlayer();
                  activity.initAudio(v.getContext(), mData.get(vHolder.getAdapterPosition()).getURL());
                  activity.setMargins(v.getRootView().findViewById(R.id.viewpager_id), 0,0,0,205);
                  activity.updateNotificationBar("mzPlay", mData.get(vHolder.getAdapterPosition()).getName());
                  MainActivity.currentPos =  vHolder.getAdapterPosition();
              }
          });
          return vHolder;
      }
  
      @Override
      public void onBindViewHolder(MyViewHolder holder, int position) {
          holder.tv_name.setText(mData.get(position).getName());
          holder.tv_author.setText(mData.get(position).getPhone());
          holder.img.setImageResource(mData.get(position).getPhoto());
  
          //Toast.makeText(activity, String.valueOf(holder), Toast.LENGTH_LONG).show();
          if(selectedPos == position){
              holder.itemView.setBackgroundColor(Color.parseColor("#373737"));
          }
          else
          {
              holder.itemView.setBackgroundColor(Color.parseColor("#212121"));
          }
      }
  
  
      @Override
      public int getItemCount() {
          return mData.size();
      }
  
  
      public static class MyViewHolder extends RecyclerView.ViewHolder {
  
          private ImageButton item_play;
          private LinearLayout menu_play;
          private TextView tv_name;
          private TextView tv_author;
          private ImageView img;
  
          public MyViewHolder(View itemView) {
              super(itemView);
              item_play = itemView.findViewById(R.id.info_id);
              menu_play = itemView.findViewById(R.id.list_item_id);
  
              tv_name = itemView.findViewById(R.id.name_list);
              tv_author = itemView.findViewById(R.id.author_list);
              img = itemView.findViewById(R.id.img_music);
          }
      }
  }
  </code></pre>
  
  <p>Video: <a href="https://ntcdn.stream/20181009_2342010.mp4" rel="nofollow noreferrer">https://ntcdn.stream/20181009_2342010.mp4</a></p>
  
  <p>The problem is: I must swipe the page to item colors be updated, how can I update the colors without page swipe?</p>