title: I want to apply an onclicklistener to a textview inside a cardview WITHOUT RECYCLER VIEW. My code is as follows
body: <p>xml layout</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.design.widget.CoordinatorLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
  
  
  
      &lt;android.support.v4.widget.NestedScrollView
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          app:layout_behavior="@string/appbar_scrolling_view_behavior"
          app:layout_scrollFlags="scroll|enterAlways"&gt;
  
          &lt;LinearLayout
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="vertical"
              android:paddingTop="24dp"
              android:background="@color/back"
              &gt;
  
              &lt;android.support.v7.widget.CardView
                  android:layout_height="wrap_content"
                  android:layout_width="match_parent"
                  android:layout_margin="16dp"
                  android:layout_marginBottom="16dp"
                  android:layout_marginLeft="16dp"
                  android:layout_marginRight="16dp"&gt;
                  &lt;LinearLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:orientation="vertical"
                      android:layout_margin="16dp"
                      &gt;
                      &lt;TextView
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:text="Central Library"
                          android:textSize="18dp"
                          android:id="@+id/lib"/&gt;
  
  
                  &lt;/LinearLayout&gt;
  
              &lt;/android.support.v7.widget.CardView&gt;
  
              &lt;android.support.v7.widget.CardView
                  android:layout_height="wrap_content"
                  android:layout_width="match_parent"
                  android:layout_margin="16dp"
                  android:layout_marginBottom="16dp"
                  android:layout_marginLeft="16dp"
                  android:layout_marginRight="16dp"&gt;
                  &lt;LinearLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:orientation="vertical"
                      android:layout_margin="16dp"&gt;
                      &lt;TextView
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:text="Dispensary"
                          android:textSize="18dp"
                          android:id="@+id/dis"/&gt;
  
  
                  &lt;/LinearLayout&gt;
  
              &lt;/android.support.v7.widget.CardView&gt;
  
              &lt;android.support.v7.widget.CardView
                  android:layout_height="wrap_content"
                  android:layout_width="match_parent"
                  android:layout_margin="16dp"
                  android:layout_marginBottom="16dp"
                  android:layout_marginLeft="16dp"
                  android:layout_marginRight="16dp"&gt;
                  &lt;LinearLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:orientation="vertical"
                      android:layout_margin="16dp"&gt;
                      &lt;TextView
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:text="Auditorium"
                          android:textSize="18dp"
                          android:id="@+id/audi"/&gt;
  
  
                  &lt;/LinearLayout&gt;
  
              &lt;/android.support.v7.widget.CardView&gt;
              &lt;android.support.v7.widget.CardView
                  android:layout_height="wrap_content"
                  android:layout_width="match_parent"
                  android:layout_margin="16dp"
                  android:layout_marginBottom="16dp"
                  android:layout_marginLeft="16dp"
                  android:layout_marginRight="16dp"&gt;
                  &lt;LinearLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:orientation="vertical"
                      android:layout_margin="16dp"&gt;
                      &lt;TextView
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:text="Bank and ATM"
                          android:textSize="18dp"
                          android:id="@+id/atm"/&gt;
  
  
                  &lt;/LinearLayout&gt;
  
              &lt;/android.support.v7.widget.CardView&gt;
              &lt;android.support.v7.widget.CardView
                  android:layout_height="wrap_content"
                  android:layout_width="match_parent"
                  android:layout_margin="16dp"
                  android:layout_marginBottom="16dp"
                  android:layout_marginLeft="16dp"
                  android:layout_marginRight="16dp"&gt;
                  &lt;LinearLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:orientation="vertical"
                      android:layout_margin="16dp"&gt;
                      &lt;TextView
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:text="VIP Guest House"
                          android:textSize="18dp"
                          android:id="@+id/gh"/&gt;
  
  
                  &lt;/LinearLayout&gt;
  
              &lt;/android.support.v7.widget.CardView&gt;
  
          &lt;/LinearLayout&gt;
  
      &lt;/android.support.v4.widget.NestedScrollView&gt;
  
  
  &lt;/android.support.design.widget.CoordinatorLayout&gt;
  </code></pre>
  
  <p>java code..</p>
  
  <pre><code>package com.example.hp.manit;
  
  import android.content.Intent;
  import android.os.Bundle;
  import android.support.design.widget.FloatingActionButton;
  import android.support.design.widget.Snackbar;
  import android.support.v7.app.AppCompatActivity;
  import android.support.v7.widget.CardView;
  import android.support.v7.widget.RecyclerView;
  import android.support.v7.widget.Toolbar;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.TextView;
  
  //code starts from here
  
  public class Facilities extends AppCompatActivity implements View.OnClickListener{
  
      Intent intent;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_facilities);
          Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
          setSupportActionBar(toolbar);
  
          TextView t1=(TextView)findViewById(R.id.lib);
          t1.setOnClickListener(this);
          TextView t2=(TextView)findViewById(R.id.dis);
          t2.setOnClickListener(this);
          TextView t3=(TextView)findViewById(R.id.audi);
          t3.setOnClickListener(this);
          TextView t4=(TextView)findViewById(R.id.atm);
          t4.setOnClickListener(this);
          TextView t5=(TextView)findViewById(R.id.gh);
          t5.setOnClickListener(this);
  
  
      }
  
      @Override
      public void onClick(View v) {
  
          switch (v.getId()) {
  
              case R.id.lib:
                  // do your code
                  intent = new Intent(Facilities.this, Library.class);
                  startActivity(intent);
                  break;
  
              case R.id.dis:
                  // do your code
                  intent = new Intent(Facilities.this, Library.class);
                  startActivity(intent);
                  break;
  
              case R.id.audi:
                  // do your code
                  intent = new Intent(Facilities.this, Auditorium.class);
                  startActivity(intent);
                  break;
              case R.id.atm:
                  // do your code
                  intent = new Intent(Facilities.this, BankATM.class);
                  startActivity(intent);
                  break;
              case R.id.gh:
                  // do your code
                  intent = new Intent(Facilities.this, GuestHouse.class);
                  startActivity(intent);
                  break;
          }
  
      }
  }
  </code></pre>
  
  <p>NOTE: This layout file facilities.xml is inflated in a fragment inside a tab layout.</p>
  
  <pre><code> public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      Bundle args = getArguments();
      int tabPositon = args.getInt(TAB_POSITION);
  
      if(tabPositon==0) {
          View v0 = inflater.inflate(R.layout.activity_academics, container, false);
  
          return v0;
      }
      else if(tabPositon==1) {
          View v1 = inflater.inflate(R.layout.activity_departments, container, false);
  
          return v1;
      }
      else if(tabPositon==2) {
          View v2 = inflater.inflate(R.layout.activity_facilities, container, false);
  
          return v2;
      }
      else {
  
          View v3 = inflater.inflate(R.layout.activity_students_zone, container, false);
  
          return v3;
      }
  
  }
  </code></pre>
  
  <p>Ive applied a listener to each textview for opening a new activity using intent.
  But its not working</p>
  
  <p>I just want to open a new activity on clicking a cardview
  Plz help how ?????</p>