title: Cardviews not showing after back pressed
body: <p>I've successfully implemented <a href="https://code.tutsplus.com/tutorials/getting-started-with-recyclerview-and-cardview-on-android--cms-23465" rel="nofollow noreferrer">cardview and recycleview</a> in my navigation drawer. Now the problem is, when ever I clicked in my first cardview which will take me to my first fragment and then press <strong>back</strong>, my cardviews aren't in my list tab(1st fragment) anymore. The only option view the list of cardviews is to swipe to my navigation drawer again and click on the first fragment to view the cardviews.</p>
  
  <p>here's my code for the
  <strong>RecyclerViewAdapter.class</strong></p>
  
  <pre><code>package com.example.guitarista.citem.Exhibitor;
  
  import android.content.Context;
  import android.content.Intent;
  import android.support.v7.app.AppCompatActivity;
  import android.support.v7.widget.RecyclerView;
  import android.support.v7.widget.CardView;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ImageView;
  import android.widget.TextView;
  
  import com.example.guitarista.citem.Gallery_SpringForward.GalleryFragment;
  import com.example.guitarista.citem.Gallery_activity.GalleryActivity;
  import com.example.guitarista.citem.R;
  import java.util.List;
  
  
  
  /**
   * Created by smdojt on 1/24/2017.
   */
  
  public class TabInt_RV_Adapter extends RecyclerView.Adapter&lt;TabInt_RV_Adapter.ItemViewHolder&gt; {
  
      public static class ItemViewHolder extends RecyclerView.ViewHolder {
          static CardView cv;
          TextView itemName;
          TextView itemCathegory;
          ImageView itemPhoto;
  
          ItemViewHolder(View itemView) {
              super(itemView);
              cv = (CardView)itemView.findViewById(R.id.cv);
              itemName = (TextView) itemView.findViewById(R.id.item_name);
              itemCathegory = (TextView) itemView.findViewById(R.id.item_cathegory);
              itemPhoto = (ImageView) itemView.findViewById(R.id.item_photo);
          }
      }
  
      List&lt;Exhibitors_Int&gt; items;
      Context context;
      TabInt_RV_Adapter(List&lt;Exhibitors_Int&gt; items, Context context) {
          this.context = context;
          this.items = items;
      }
  
  
      @Override
      public void onAttachedToRecyclerView(RecyclerView recyclerView) {
          super.onAttachedToRecyclerView(recyclerView);
      }
  
      @Override
      public ItemViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
          View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.fragment_exhibitor_tabint_item, viewGroup, false);
          ItemViewHolder ivh = new ItemViewHolder(v);
          return ivh;
      }
  
      @Override
      public void onBindViewHolder(ItemViewHolder itemViewHolder, final int i) {
          itemViewHolder.cv.setOnClickListener(null);
          itemViewHolder.itemName.setText(items.get(i).name);
          itemViewHolder.itemCathegory.setText(items.get(i).cathegory);
          itemViewHolder.itemPhoto.setImageResource(items.get(i).photoId);
  
          ItemViewHolder.cv.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  if (i == 1) {
                      //Toast.makeText(context, "Index position is 1", Toast.LENGTH_SHORT).show();
                      Intent intent = new Intent (context, GalleryActivity.class);
                      context.startActivity(intent);
                  }
                  else if (i == 2) {
                      //Toast.makeText(context, "Index position is 2 ", Toast.LENGTH_SHORT).show();
                      AppCompatActivity activity = (AppCompatActivity) v.getContext();
                      GalleryFragment gf = new GalleryFragment();
                      activity.getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, gf).addToBackStack(null).commit();
                  }
  
              }
          });
      }
  
      @Override
      public int getItemCount() {
          return items.size();
      }
  
  
  }
  </code></pre>
  
  <p>notice that on my onClick, there's two versions of gallery. The first one is the original activity, and the second one is implemented for fragment.</p>
  
  <p>So when I clicked on the first one, and then back pressed, the cardviews will show. Now whats the problem with this? I cant swipe through navigation drawer when I click the activity version of gallery.</p>
  
  <p>Where in, when I clicked on the second cardview which is fragment implemented, the navigation drawer swipe does work while inside the gallery, but when I press back, the lists of cardviews wont show.</p>
  
  <p>even when I put these lines of code for fragment:</p>
  
  <pre><code>GalleryFragment fr = new GalleryFragment();
                       Bundle args = new Bundle();
                       fr.setArguments(args);
                       FragmentManager fm = getFragmentManager();
                       FragmentTransaction fragmentTransaction = fm.beginTransaction();
                       fragmentTransaction.replace(R.id.fragment_container, fr);
                       fragmentTransaction.addToBackStack(null);
                       fragmentTransaction.commit();
  </code></pre>
  
  <p>I'll just even get an error for <strong>getFragmentManager();</strong></p>
  
  <p>Is there any other way to solve this?</p>
  
  <p><strong>CODE FOR CARDVIEWS</strong></p>
  
  <pre><code>package com.example.guitarista.citem.Exhibitor;
  
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.support.v7.widget.LinearLayoutManager;
  import android.support.v7.widget.RecyclerView;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  
  import com.example.guitarista.citem.R;
  
  import java.util.ArrayList;
  import java.util.List;
  
  /**
   * A simple {@link Fragment} subclass.
   */
  public class TabInternationalFragment extends Fragment {
  
      private List&lt;Exhibitors_Int&gt; items;
      private RecyclerView rv;
  
      public TabInternationalFragment() {
          // Required empty public constructor
      }
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          // Inflate the layout for this fragment
          View v = inflater.inflate(R.layout.fragment_exhibitor_tab_international, container, false);
  
          rv=(RecyclerView)v.findViewById(R.id.rv);
          LinearLayoutManager llm = new LinearLayoutManager(getActivity());
          rv.setLayoutManager(llm);
          //GridLayoutManager glm = new GridLayoutManager(getActivity(), 4);
          //rv.setLayoutManager(glm);
          rv.setHasFixedSize(true);
  
          initializeData();
          initializeAdapter();
          return v;
      }
  
      private void initializeData() {
          items = new ArrayList&lt;&gt;();
          items.add(new Exhibitors_Int("A. GARCIA CRAFTS", "FURNITURE", R.drawable.image1));
          items.add(new Exhibitors_Int("BALEX BOXES", "HOLIDAY DECORATION", R.drawable.image2));
          items.add(new Exhibitors_Int("CAGAYAN DE ORO HANDMADE PAPER", "HOME DECOR/HOUSEWARE", R.drawable.image3));
      }
  
      private void initializeAdapter(){
          TabInt_RV_Adapter adapter = new TabInt_RV_Adapter(items, getContext());
          rv.setAdapter(adapter);
  
      }
  
  }
  </code></pre>