title: How to dynamically change item view in recycler view?
body: <p>I am writing music player with track list in  recycler view. I want to change image view in clicked item. Tried to use getItemViewType, but as I can understand it sets view type only once. Here's my code:</p>
  
  <pre><code>public class TrackListAdapter extends RecyclerView.Adapter&lt;TrackListAdapter.RegularViewHolder&gt; implements IntConstants{
  
  private ArrayList&lt;Track&gt; trackList;
  private Context context;
  int selectedPos = -1;
  
  public TrackListAdapter(ArrayList&lt;Track&gt; trackList, Context context) {
      this.trackList = trackList;
      this.context = context;
      EventBus.getDefault().register(this);
  }
  
  @Override
  public void onDetachedFromRecyclerView(RecyclerView recyclerView) {
      EventBus.getDefault().unregister(this);
      super.onDetachedFromRecyclerView(recyclerView);
  }
  
  @Override
  public RegularViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
      RecyclerView.LayoutParams params = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
      if (viewType == ITEM_TYPE_PLAYING){
          //here i am sending xml for clicked item
          View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.playing_track_item, parent, false);
          return new RegularViewHolder(itemView) ;
      }else {
          //here i'm sending xml for regular item
          View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.regular_track_item, parent, false);
          return new RegularViewHolder(itemView) ;
      }
  }
  
  @Override
  public void onBindViewHolder(final RegularViewHolder holder, int position) {
      Track t = trackList.get(position);
      holder.textTrackTitle.setText(t.getTitle());
      holder.textTrackAlbum.setText(t.getAlbum());
      holder.textTrackArtist.setText(t.getArtist());
      holder.parent.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              EventBus.getDefault().post(new MessageEvent(TRACK_CLICKED_ACTION_CODE, holder.getAdapterPosition()));
          }
      });
  }
  
  @Override
  public int getItemCount() {
      return trackList.size();
  }
  
  class RegularViewHolder extends RecyclerView.ViewHolder{
      ImageView imageAlbumArt;
      TextView textTrackTitle, textTrackArtist, textTrackAlbum;
      RelativeLayout parent;
  
      private RegularViewHolder(View itemView){
          super(itemView);
          parent = (RelativeLayout)itemView.findViewById(R.id.item_parent);
          imageAlbumArt = (ImageView)itemView.findViewById(R.id.image_album_art);
          textTrackTitle = (TextView) itemView.findViewById(R.id.text_track_title);
          textTrackArtist = (TextView) itemView.findViewById(R.id.text_track_artist);
          textTrackAlbum = (TextView) itemView.findViewById(R.id.text_track_album);
      }}
  
  @Override
  public int getItemViewType(int position) {
      if (position == selectedPos){
          return ITEM_TYPE_PLAYING;
      }else {
          return ITEM_TYPE_REGULAR;
      }
  }
  
  @Subscribe
  public void handleTrack(MessageEvent event){
      if (event.getCode() == TRACK_SELECTED_ACTION_CODE){
          selectedPos = event.getPosition();
      }
  }
  </code></pre>
  
  <p>}</p>