title: Passing RecyclerView CardView Clicked Item Data To Activity
body: <p>I have a question about passing clicked cardview data to activity, and here the full story :</p>
  
  <ol>
  <li><p>I have an Activity called "Details", which contains 2 TextViews in it's layout, Title &amp; Description .</p></li>
  <li><p>I have setup a fragment ( tab_1 ) which contain the recyclerview codes and the the items data, each item of those contain : title &amp; description .</p></li>
  </ol>
  
  <p>What i want : </p>
  
  <p>When the user click the item, it will open the Details Activity, and change Details layout title, with clicked item title, and the same for description .</p>
  
  <p>I've manged to create the other activity as an example, and made intent to start it, plus adding "addOnTouchlistener" thanks to Stackoverflow, i've found the way to make it .</p>
  
  <p>So, how to make this alive? I've tried many ways of the available answers on Stackoverflow, but all of them not working, or not related to my request .</p>
  
  <p>Here are my files : </p>
  
  <p>itemsdata.java :</p>
  
  <pre><code>public class itemsdata {
  int CatPic;
  String title;
  String Descr;
  int Exapnd;
  int expand_no;
  </code></pre>
  
  <p>tab_1.java ( fragment ) </p>
  
  <pre><code>public class tab_1 extends Fragment implements SearchView.OnQueryTextListener {
  
  private RecyclerView mRecyclerView;
  public RecyclingViewAdapter adapter;
  private Activity context;
  @Override
  public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
      View layout = inflater.inflate(R.layout.tab_1, container, false);
      mRecyclerView = (RecyclerView)layout.findViewById(R.id.recycler_view);
      mRecyclerView.addOnItemTouchListener(new RecyclerItemClickListener
              (getContext(), new RecyclerItemClickListener.OnItemClickListener() {
  
                  @Override
                  public void onItemClick(View view, int position) {
                      Intent i = new Intent(view.getContext(), DetailsActivity.class);
                      view.getContext().startActivity(i);
                  }
              }));
      mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
      adapter = new RecyclingViewAdapter(getActivity(),Listed());
      mRecyclerView.setAdapter(adapter);
      return layout;
  
  }
  
  
  @Override
  public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
      inflater.inflate(R.menu.main, menu);
  
      final MenuItem item = menu.findItem(R.id.action_search);
      final SearchView searchView = (SearchView) MenuItemCompat.getActionView(item);
      searchView.setOnQueryTextListener(this);
  }
  
  @Override
  public boolean onQueryTextChange(String query) {
      final List&lt;itemsdata&gt; filteredModelList = filter(Listed(), query);
      adapter.animateTo(filteredModelList);
      mRecyclerView.scrollToPosition(0);
      return true;
  }
  
  @Override
  public boolean onQueryTextSubmit(String query) {
      return true;
  }
  
  private List&lt;itemsdata&gt; filter(List&lt;itemsdata&gt; models, String query) {
      query = query.toLowerCase();
  
      final List&lt;itemsdata&gt; filteredModelList = new ArrayList&lt;&gt;();
      for (itemsdata model : models) {
          final String text = model.title.toLowerCase();
          if (text.contains(query)) {
              filteredModelList.add(model);
          }
      }
      return filteredModelList;
  }
  
  public List&lt;itemsdata&gt; Listed()
  {
      //Titles Strings
      String sys_title1 = getString(R.string.system_item_title_1);
      String sys_title2 = getString(R.string.system_item_title_2);
      String sys_title3 = getString(R.string.system_item_title_3);
  
      //Description Strings
      String sys_descr1 = getString(R.string.system_item_desc_1);
      String sys_descr2 = getString(R.string.system_item_desc_2);
      String sys_descr3 = getString(R.string.system_item_desc_3);
  
      //Adding New Cards
      List&lt;itemsdata&gt; data = new ArrayList&lt;&gt;();
  
      //Categories Icons New Items ** Make It The Same
      int[] icons = {
              R.drawable.facebook_icon ,
              R.drawable.twitter_icon ,
              R.drawable.twitter_icon
      };
  
      //Expand Button New Items
      int[] expandbutton = {
              R.drawable.expanded ,
              R.drawable.expanded ,
              R.drawable.expanded
      };
  
      //UnExpand Button New Items
      int[] unexpandbutton = {
              R.drawable.ca_expand ,
              R.drawable.ca_expand ,
              R.drawable.ca_expand
      };
  
      //Titles New Items
      String[] titles = {
              sys_title1 ,
              sys_title2 ,
              sys_title3
      };
  
      //Description New Items
      String[] Description = {
              sys_descr1 ,
              sys_descr2 ,
              sys_descr3
      };
  
  
      for(int i = 0;i&lt;titles.length &amp;&amp; i &lt; icons.length  &amp;&amp; i &lt; Description.length &amp;&amp; i &lt; unexpandbutton.length &amp;&amp; i &lt; expandbutton.length  ; i++)
      {
          itemsdata current = new itemsdata();
          current.CatPic = icons[i];
          current.title = titles[i];
          current.Descr = Description[i];
          current.expand_no = unexpandbutton[i];
          current.Exapnd = expandbutton[i];
          data.add(current);
      }
      return data;
  }
  
  }
  </code></pre>
  
  <p>Details Activity : </p>
  
  <pre><code>public class DetailsActivity extends AppCompatActivity{
  
  TextView title;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
  
      super.onCreate(savedInstanceState);
      setContentView(R.layout.details);
      title = (TextView)findViewById(R.id.details_title);
  }
  </code></pre>
  
  <p>EDIT : I've made it, i have added a button which open the fragment, and passed the data, in the Adapter, but i want it via tab_1.java, not the Adapter, i mean i want to click on the item to open the fragment, not on a button, here a snap from my Adapter code ( i've added it in OnBindViewHolder ) </p>
  
  <p>I've setup a OnClick and implemented the Vew.setOnClick ..etc, but when i click the item, nothing happen.</p>
  
  <pre><code> @Override
  public void onBindViewHolder(final MyRecycleViewHolder holder, int position) {
  
      holder.itemView.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              Intent i = new Intent(v.getContext(),DetailsActivity.class);
              v.getContext().startActivity(i);
          }
      });
  
      //Referencing Data
      final itemsdata currentobject = mdata.get(position);
      //Referencing Items
      holder.ProbTitle.setText(currentobject.title);
      holder.ProbDescr.setText(currentobject.Descr);
      holder.CategoryPic.setImageResource(currentobject.CatPic);
      holder.ExpandButton.setImageResource(currentobject.Exapnd);
      holder.ExpandNoButton.setImageResource(currentobject.expand_no);
          //What Happen When You Click Expand Button .
      holder.ExpandButton.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              Intent i = new Intent(v.getContext(), DetailsActivity.class);
              i.putExtra("TitleKey",holder.ProbTitle.getText().toString());
              v.getContext().startActivity(i);
              }
          }
      );
  
  public static class MyRecycleViewHolder extends RecyclerView.ViewHolder
  {
  
  
  
      SwipeLayout swipeLayout;
      //Defining Items .
      TextView ProbTitle;
      ImageButton ExpandButton;
      TextView ProbDescr;
      ImageButton ExpandNoButton;
      ImageView CategoryPic;
      /*
      TextView Card_Star;
      TextView Card_UnStar;
      */
      TextView Card_Share;
  
      //Referencing Resources
      public MyRecycleViewHolder(final View itemView) {
          super(itemView);
          ProbTitle = (TextView) itemView.findViewById(R.id.prob_title);
          CategoryPic = (ImageView) itemView.findViewById(R.id.cat_pic);
          ProbDescr = (TextView) itemView.findViewById(R.id.prob_descr);
          ExpandButton = (ImageButton) itemView.findViewById(R.id.expand_button);
          ExpandNoButton = (ImageButton) itemView.findViewById(R.id.expand_no_button);
          /*
          Card_Star = (TextView) itemView.findViewById(R.id.card_star);
          Card_UnStar = (TextView) itemView.findViewById(R.id.card_unstar);
          */
          Card_Share = (TextView) itemView.findViewById(R.id.card_share);
          swipeLayout = (SwipeLayout) itemView.findViewById(R.id.swipe);
  
      }
  </code></pre>