title: RecyclerView and CardView Click listener implementation
body: <p>I just moved into the android RecyclerView and CardViewand ... and realized recyclerview don't have an option for Onclick listner, but after implement this feature, i just don't see any result.</p>
  
  <p>hear is my code and layouts:</p>
  
  <p><strong>MainActivity:</strong></p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      //private usefulSites_RecyclerView_Adapter mAdapter;
      final Context context = this;
      private RecyclerView mRecyclerView;
      private StaggeredGridLayoutManager mGridLayoutManager;
      private RecyclerViewAdapter mAdapter;
      private String[] mList;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
          setSupportActionBar(mToolbar);
          getSupportActionBar().setDisplayHomeAsUpEnabled(true);
          mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  onBackPressed();
              }
          });
          //使用CollapsingToolbarLayout必须把title设置到CollapsingToolbarLayout上，设置到Toolbar上则不会显示
          CollapsingToolbarLayout mCollapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar_layout);
          mCollapsingToolbarLayout.setTitle("test");
          //通过CollapsingToolbarLayout修改字体颜色
          mCollapsingToolbarLayout.setExpandedTitleColor(Color.WHITE);//设置还没收缩时状态下字体颜色
          mCollapsingToolbarLayout.setCollapsedTitleTextColor(Color.GREEN);
  
  
          //mList = getResources().getStringArray(R.array.numbers);
  
          mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView);
          mGridLayoutManager = new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL);
          mRecyclerView.setItemAnimator(new DefaultItemAnimator());
          mRecyclerView.setLayoutManager(mGridLayoutManager);
          mAdapter = new RecyclerViewAdapter(getApplicationContext());
          mRecyclerView.setAdapter(mAdapter);
  
  
      }
  
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.menu_main, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // Handle action bar item clicks here. The action bar will
          // automatically handle clicks on the Home/Up button, so long
          // as you specify a parent activity in AndroidManifest.xml.
          int id = item.getItemId();
  
          //noinspection SimplifiableIfStatement
          if (id == R.id.action_settings) {
              return true;
          }
  
          return super.onOptionsItemSelected(item);
      }
  }
  </code></pre>
  
  <p><strong>RecyclerViewAdapter</strong></p>
  
  <pre><code>public class RecyclerViewAdapter extends RecyclerView.Adapter&lt;RecyclerViewAdapter.ViewHolder&gt; {
  
      private Context mContext;
      private String [] mSiteTitle,mSiteLink;
      private int [] mThumbnail;
  
      public RecyclerViewAdapter(Context contexts, String[] list) {
          this.mContext = contexts;
          this.mSiteTitle = list;
      }
      public RecyclerViewAdapter(Context contexts) {
          this.mContext = contexts;
          initList();
      }
      private void initList(){
  
          UsfulSite_init mInit=new UsfulSite_init();
          mSiteTitle= mInit.initSiteTitle();
          mSiteLink=mInit.initSiteLink();
          mThumbnail=mInit.initThumbnail();
  
  
      }
  
      @Override
      public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          LayoutInflater inflater = LayoutInflater.from(parent.getContext());
          View itemView = inflater.inflate(R.layout.usful_sites_card_view, parent, false);
          return new ViewHolder(itemView);
      }
  
      @Override
      public void onBindViewHolder(ViewHolder holder, int position) {
          holder.sTitle.setText(mSiteTitle[position]);
          holder.sLink.setText(mSiteTitle[position]);
          holder.sImage.setImageResource(mThumbnail[position]);
  
  
          holder.setClickListener(new ItemClickListener() {
              @Override
              public void onClick(View view, int position, boolean isLongClick) {
                  if (isLongClick) {
                      Toast.makeText(mContext, "#" + position + " - " + mSiteTitle[position] + " (Long click)", Toast.LENGTH_SHORT).show();
                  } else {
                      Toast.makeText(mContext, "#" + position + " - " + mSiteTitle[position], Toast.LENGTH_SHORT).show();
                  }
              }
          });
      }
  
      @Override
      public int getItemCount() {
          return mSiteTitle.length;
      }
  
      public static class ViewHolder extends RecyclerView.ViewHolder
              implements View.OnClickListener, View.OnLongClickListener{
          private TextView sTitle,sLink;
          private ImageView sImage;
          private ItemClickListener clickListener;
  
          public ViewHolder(View itemView) {
              super(itemView);
              sTitle = (TextView)itemView.findViewById(R.id.useful_sites_Title);
              sLink=(TextView)itemView.findViewById(R.id.useful_sites_Link);
              sImage=(ImageView)itemView.findViewById(R.id.useful_sites_thumbnail);
              itemView.setTag(itemView);
              itemView.setOnClickListener(this);
              itemView.setOnLongClickListener(this);
  
  
          }
  
          public void setClickListener(ItemClickListener itemClickListener) {
              this.clickListener = itemClickListener;
          }
  
          @Override
          public void onClick(View view) {
              clickListener.onClick(view, getPosition(), false);
          }
  
          @Override
          public boolean onLongClick(View view) {
              clickListener.onClick(view, getPosition(), true);
              return true;
          }
      }
  }
  </code></pre>
  
  <p><strong>Activity_main.xml:</strong></p>
  
  <pre><code>&lt;android.support.design.widget.CoordinatorLayout
  android:id="@+id/coordinatorLayout"
  
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context=".MainActivity"&gt;
  &lt;android.support.design.widget.AppBarLayout
  
      android:layout_width="match_parent"
      android:layout_height="256dp"
      android:fitsSystemWindows="true"&gt;
      &lt;android.support.design.widget.CollapsingToolbarLayout
          android:id="@+id/collapsing_toolbar_layout"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
  
          app:contentScrim="#30469b"
          app:expandedTitleMarginStart="48dp"
          app:layout_scrollFlags="scroll|exitUntilCollapsed"&gt;
          &lt;ImageView
  
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:scaleType="centerCrop"
              android:src="@drawable/a"
              app:layout_collapseMode="parallax"
              app:layout_collapseParallaxMultiplier="0.7"  /&gt;
          &lt;android.support.v7.widget.Toolbar
              android:id="@+id/toolbar"
              android:layout_width="match_parent"
              android:layout_height="?attr/actionBarSize"
              app:layout_collapseMode="pin" /&gt;
      &lt;/android.support.design.widget.CollapsingToolbarLayout&gt;
  &lt;/android.support.design.widget.AppBarLayout&gt;
  &lt;LinearLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      app:layout_behavior="@string/appbar_scrolling_view_behavior"&gt;
      &lt;android.support.v7.widget.RecyclerView
          android:id="@+id/recyclerView"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:scrollbars="none" /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>CardView  Layout.xml:</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="horizontal" android:layout_width="match_parent"
  xmlns:card_view="http://schemas.android.com/apk/res-auto"
  android:layout_margin="5dp"
  card_view:cardCornerRadius="5dp"
  card_view:cardElevation="4dp"
  android:layout_height="match_parent"&gt;
  
  &lt;RelativeLayout
  
      android:id="@+id/mainHolder"
      android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
  
      &lt;ImageView
          android:id="@+id/useful_sites_thumbnail"
          android:layout_width="match_parent"
          android:layout_height="100dp"
          android:scaleType="centerCrop"
          android:tint="@color/photo_tint"
          android:layout_centerInParent="true"
          /&gt;
  
      &lt;TextView
          android:id="@+id/useful_sites_Title"
          android:gravity="center"
          android:background="?android:selectableItemBackground"
          android:focusable="true"
          android:clickable="true"
          android:layout_width="match_parent"
          android:layout_height="100dp"
          android:textSize="24sp"
          android:layout_centerInParent="true"
          android:textColor="@android:color/white"
          /&gt;
      &lt;TextView
          android:id="@+id/useful_sites_Link"
          android:gravity="center"
          android:background="?android:selectableItemBackground"
          android:focusable="true"
          android:clickable="true"
          android:layout_width="match_parent"
          android:layout_height="100dp"
          android:textSize="24sp"
          android:layout_centerInParent="true"
          android:textColor="@android:color/white"
          android:visibility="gone"
          /&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p></p>
  
  <p>I tested another ways for clickListner in RV butT, i just stuck in this.
  can some one look at my code and guide me, Little about this.</p>