title: How open fragment from RecyclerView.Adapter<CardAdapter.ViewHolder>
body: <ol>
  <li><p>TabLayout</p>
  <ul>
  <li>tab1 (Fragment1)</li>
  <li>tab2 (Fragment2)</li>
  <li>tab3 (Fragment3)
  <ul>
  <li>RecyclerView + CardView (OnClick)</li>
  </ul>
  </li>
  </ul>
  </li>
  </ol>
  <p>On <code>CardView</code> ClickListner open another fragment in tab3. So how to open fragment in tab3.</p>
  <p>Error is in <code>getFragmentManager()</code>:</p>
  <pre><code>FragmentTransaction transaction = getFragmentManager().beginTransaction();
  </code></pre>
  <p>which gives</p>
  <pre><code>/Adapter/CardAdapter.java Error:cannot find symbol method getSupportFragmentManager()
  </code></pre>
  <p>Instead of this, I tried:</p>
  <pre><code>FragmentTransaction transaction = activity.getFragmentManager().beginTransaction();
  FragmentTransaction transaction = itemview.getContext().getFragmentManager().beginTransaction();
  </code></pre>
  <p>But error is not resolve.</p>
  <p>Here is my code:</p>
  <pre><code> public class CardAdapter extends RecyclerView.Adapter&lt;CardAdapter.ViewHolder&gt; {
  
      List&lt;NatureItem&gt; mItems;
      private int lastPosition = -1;
      Context context;
      TaskFragment main;
      public CardAdapter(Context context,TaskFragment ma)
      {
  
          this.context=context;
          main=ma;
      }
  
  
      public CardAdapter() {
          super();
          mItems = new ArrayList&lt;NatureItem&gt;();
          NatureItem nature = new NatureItem();
          nature.setName(&quot;The Paris Attack 2015&quot;);
          nature.setDes(&quot;Lorem ipsum dolor sit amet.&quot;);
          nature.setThumbnail(R.drawable.news1);
          mItems.add(nature);
  
             }
  
  
  
      @Override
      public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int position) {
          View v = LayoutInflater.from(viewGroup.getContext())
                  .inflate(R.layout.custom_list, viewGroup, false);
          ViewHolder viewHolder = new ViewHolder(v);
  
       return viewHolder;
      }
  
    
       @Override
      public void onBindViewHolder(ViewHolder viewHolder, int i) {
          NatureItem nature = mItems.get(i);
          viewHolder.tvNature.setText(nature.getName());
          viewHolder.tvDesNature.setText(nature.getDes());
          viewHolder.imgThumbnail.setImageResource(nature.getThumbnail());
        //  setAnimation(viewHolder.card,i);
      }
  
     
      @Override
      public int getItemCount() {
          return mItems.size();
      }
  
      class ViewHolder extends RecyclerView.ViewHolder {
  
          private int lastPosition = -1;
          public ImageView imgThumbnail;
          public TextView tvNature;
          public TextView tvDesNature;
         // Button btnclear,btncancle;
          CardView card;
          Activity activity;
          Context co;
          public ViewHolder(final View itemView) {
              super(itemView);
              imgThumbnail = (ImageView)     itemView.findViewById(R.id.img_thumbnail);
              tvNature = (TextView) itemView.findViewById(R.id.tv_nature);
              tvDesNature = (TextView) itemView.findViewById(R.id.tv_des_nature);
              card = (CardView) itemView.findViewById(R.id.card);
  
  
  
      card.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
          
          Toast.makeText(itemView.getContext(), &quot;Clicked Card...&quot;, Toast.LENGTH_LONG).show();
         
             ShareFragment newFragment = new ShareFragment();
              FragmentTransaction transaction =  getFragmentManager().beginTransaction();
              transaction.replace(R.id.viewFragments, newFragment);
              transaction.addToBackStack(null);
              transaction.commit();
  
              }
      });
          
          }
      }
  }
          
  </code></pre>