Select position of CardView in RecyclerView and Change Fragment in RecyclerView : <p><strong>* EASY PART *</strong></p>

<p>At the moment I have set up a CardView inside a RecyclerView.</p>

<p>What i need to do is to change the color of the 2nd cardview to yellow, and the 3rd cardview to red (At the moment they are all green). Also i want the first cardview to remain green.</p>

<p><strong>* HARD PART *</strong></p>

<p>What i also need, is to be able to switch to another fragment, whenever i click on one of the CardViews in the RecyclerView. So basically to switch fragments in my RecyclerAdapter.</p>

<p>My RecyclerAdapter Java class is as follows:</p>

<p>Thanks in advance!`</p>

<pre><code>public class RecyclerAdapter extends RecyclerView.Adapter&lt;RecyclerAdapter.RecyclerViewHolder&gt; {

Fragment fragment;

private DataTabelFragment dataTabelFragment;

private static String[] title = new String[]{"D42DB2", "B42DC6", "CURRENTLY NOT AVAILABLE"};

private static String[] beskrivelse = new String[]{"Temperatur &amp; Humdity Sensorer", "Light Sensorer", ""};


@Override
public RecyclerViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {

    System.out.println( "DU ER KOMMET SÅ LANGT HABEBEEEEEEEEE" );

    View view = LayoutInflater.from( viewGroup.getContext() ).inflate( R.layout.fragment_card_view_tabel, viewGroup, false );

    viewGroup.setOnClickListener( new View.OnClickListener() {

        @Override
        public void onClick(View view) {

        }
    } );

    return new RecyclerViewHolder( view );
}

@Override
public void onBindViewHolder(RecyclerViewHolder recyclerViewHolder, int i) {

    recyclerViewHolder.mBeskrivelse.setText( beskrivelse[i] );
    recyclerViewHolder.mTitle.setText( title[i] );

    recyclerViewHolder.cardView.setCardBackgroundColor( Color.parseColor( "#FFCE54" ) );


    //recyclerViewHolder.cardView.setCardBackgroundColor( Color.parseColor( "#FFCE54" ) );

}

@Override
public int getItemCount() {
    return title.length;
}

class RecyclerViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

    private TextView mBeskrivelse;
    private TextView mTitle;
    private CardView cardView;

    public RecyclerViewHolder(View itemView) {
        super( itemView );

        mBeskrivelse = (TextView) itemView.findViewById( R.id.item_beskrivelse );
        mTitle = (TextView) itemView.findViewById( R.id.item_title );
        cardView = (CardView) itemView.findViewById( R.id.card_view );
        itemView.setOnClickListener( this );

    }

    @Override
    public void onClick(View v) {

        Toast.makeText( itemView.getContext(), "HEJ DU HAR TRYKKET PÅ KNAP", Toast.LENGTH_LONG ).show();

        //((FragmentActivity) itemView.getContext()).getSupportFragmentManager().beginTransaction().replace( R.id.recycler_view, new DataTabelFragment() ).commit();


    }

  }

}
</code></pre>
