title: How to open fragment from adapter class without using Intent?
body: <p>I want to call Fragment from Adapter Class but not able to do so..
  So please some method to call the fragment. I have got a method of first calling activity and then switching the fragment is there any other method</p>
  
  <p>Here is the code:</p>
  
  <pre><code>public class FanAdapter extends RecyclerView.Adapter&lt;FanAdapter.MyViewHolder&gt;
  {
  
  private Context mContext;
  private List&lt;Fan&gt; FanList;
  
  
  public class MyViewHolder extends RecyclerView.ViewHolder
  {
      public TextView testTitle;
      public CardView mCardView;
  
  
      public MyViewHolder(View view)
      {
          super(view);
          mCardView = (CardView) view.findViewById(R.id.card_view);
          testTitle = (TextView) view.findViewById(R.id.fan_name);
  
      }
  }
  
  
  public FanAdapter(Context mContext, List&lt;Fan&gt; FanList)
  {
      this.mContext = mContext;
      this.FanList = FanList;
  }
  
  @Override
  public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
  {
      View itemView = LayoutInflater.from(parent.getContext())
              .inflate(R.layout.fanslist, parent, false);
  
      return new MyViewHolder(itemView);
  }
  
  @Override
  public void onBindViewHolder(final MyViewHolder holder, final int position) {
      final Fan album = FanList.get(position);
      holder.testTitle.setText(album.getName());
  
      holder.mCardView.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              String Slecteditem= String.valueOf(position);
              Bitmap bmp = BitmapFactory.decodeResource(Resources.getSystem(), position);
              ByteArrayOutputStream stream = new ByteArrayOutputStream();
              bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
              byte[] byteArray = stream.toByteArray();
  
  
              Fragment fragment = new ProfileDisplay();
              FragmentManager fm = getActivity().getFragmentManager();
              FragmentTransaction fragmentTransaction = fm.beginTransaction();
              Bundle args = new Bundle();
              args.putString("itemname", Slecteditem);
              args.putByteArray("picture", byteArray);
              fragment.setArguments(args);
              fragmentTransaction.replace(R.id.fl_toplayout, fragment);
              fragmentTransaction.addToBackStack(null);
              fragmentTransaction.commit();
  
              Toast.makeText(mContext,"Profile"+album.getName(),Toast.LENGTH_LONG).show();
  
          }
      });
  
  
  
      // loading album cover using Glide library
  
  }
  
  @Override
  public int getItemCount()
  {
      return FanList.size();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The editor is not able to resolve getActivity() method in</p>
  
  <pre><code> FragmentManager fm = getActivity().getFragmentManager();
  </code></pre>