title: Card Layout Action Button
body: <p>I have created a card layout with four cards. </p>
  
  <p>Sample of my card can be found in the image.<a href="https://i.stack.imgur.com/B7OXF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/B7OXF.png" alt="enter image description here"></a>
  Code for dynamically creating them is below:</p>
  
  <pre><code>public class four_future extends Fragment {
      // TODO: Rename parameter arguments, choose names that match
      // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
      private static final String ARG_PARAM1 = "param1";
      private static final String ARG_PARAM2 = "param2";
  
      // TODO: Rename and change types of parameters
  
  
      public four_future() {
          // Required empty public constructor
      }
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          RecyclerView recyclerView = (RecyclerView) inflater.inflate(
                  R.layout.recycler_view, container, false);
          ContentAdapter adapter = new ContentAdapter(recyclerView.getContext());
          recyclerView.setAdapter(adapter);
          recyclerView.setHasFixedSize(true);
          recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
          return recyclerView;
      }
  
      public static class ViewHolder extends RecyclerView.ViewHolder {
          public ImageView picture;
          public TextView name;
          public TextView description;
          public ViewHolder(LayoutInflater inflater, ViewGroup parent) {
              super(inflater.inflate(R.layout.four_future, parent, false));
              picture = (ImageView) itemView.findViewById(R.id.card_image);
              name = (TextView) itemView.findViewById(R.id.card_title);
              description = (TextView) itemView.findViewById(R.id.card_text);
              // Adding Snackbar to Action Button inside card
              Button button = (Button)itemView.findViewById(R.id.action_button);
              button.setOnClickListener(new View.OnClickListener(){
                  @Override
                  public void onClick(View v) {
                      Snackbar.make(v, "Action is pressed",
                              Snackbar.LENGTH_LONG).show();
                  }
              });
  
  
          }
      }
      /**
       * Adapter to display recycler view.
       */
      public static class ContentAdapter extends RecyclerView.Adapter&lt;ViewHolder&gt; {
          // Set numbers of List in RecyclerView.
          private static final int LENGTH = 3
                  ;
  
          private final String[] mPrograms;
  
          private final Drawable[] mProgramPictures;
  
          public ContentAdapter(Context context) {
              Resources resources = context.getResources();
              mPrograms = resources.getStringArray(R.array.programs);
  
              TypedArray a = resources.obtainTypedArray(R.array.program_picture);
              mProgramPictures = new Drawable[a.length()];
              for (int i = 0; i &lt; mProgramPictures.length; i++) {
                  mProgramPictures[i] = a.getDrawable(i);
              }
              a.recycle();
          }
  
          @Override
          public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
              return new ViewHolder(LayoutInflater.from(parent.getContext()), parent);
          }
  
          @Override
          public void onBindViewHolder(ViewHolder holder, int position) {
              holder.picture.setImageDrawable(mProgramPictures[position % mProgramPictures.length]);
              holder.name.setText(mPrograms[position % mPrograms.length]);
  
          }
  
          @Override
          public int getItemCount() {
              return LENGTH;
          }
      }
  }
  </code></pre>
  
  <p>I have action button in every card. How to open different activities on clicking action buttons on different cards. As of now every action button just gives out a snack bar. If I click action button on first card, it must open first_activity.xml. How can I achieve this?</p>