title: How do I set the click method on CARD VIEW in VIEW PAGER that using ArrayList<> to add the object?
body: <h1><em>I want to make clicklistener on cardview in my viewpager to startActivity(Intent)</em></h1>
  
  <blockquote>
    <p>i've tried to make clicklistener with position in setOnPageChangeListener method, but it does not work for me. Please help.</p>
  </blockquote>
  
  <p>I want to set Intent on cardview.clicklistener, but i don't understand how to set by position, wheter using swith or if method</p>
  
  <p>HERE MY ACTIVITY CODE :</p>
  
  <pre><code>public class Activity extends AppCompatActivity {
  
  ViewPager viewPager;
  Adapter adapter;
  List&lt;Model&gt; models;
  
  @Override
  protected void onCreate(final Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity);
  
      CardView cardView = findViewById(R.id.cardViewLogin);
  
      //ImageViewPager
      models = new ArrayList&lt;&gt;();
      models.add(new Model(R.drawable.m,"title", "desc"));
      models.add(new Model(R.drawable.d,"title", "desc"));
      models.add(new Model(R.drawable.a,"title", "desc"));
  
      adapter = new Adapter(models,this);
      viewPager = findViewById(R.id.view_pager);
      viewPager.setAdapter(adapter);
      viewPager.setPadding(130,0,130,0);
  
      viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
          @Override
          public void onPageScrolled(final int position, float positionOffset, int positionOffsetPixels) {
  
          }
  
          @Override
          public void onPageSelected(final int position) {
          }
  
          @Override
          public void onPageScrollStateChanged(int state) {
  
          }
      });
  </code></pre>
  
  <p>HERE MY ADAPTER CODE :</p>
  
  <pre><code>public class Adapter extends PagerAdapter {
  
  private List&lt;Model&gt; models;
  private LayoutInflater layoutInflater;
  private Context context;
  
  public Adapter(List&lt;Model&gt; models, Context context) {
      this.models = models;
      this.context = context;
  }
  
  @Override
  public int getCount() {
      return models.size();
  }
  
  @Override
  public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
      return view.equals(object);
  }
  
  @NonNull
  @Override
  public Object instantiateItem(@NonNull ViewGroup container, int position) 
   {
      layoutInflater = LayoutInflater.from(context);
      View view = layoutInflater.inflate(R.layout.item,container,false);
  
      ImageView imageView;
      TextView title, desc;
  
      imageView = view.findViewById(R.id.image);
      title = view.findViewById(R.id.title);
      desc = view.findViewById(R.id.desc);
  
      imageView.setImageResource(models.get(position).getImage());
      title.setText(models.get(position).getTitle());
      desc.setText(models.get(position).getDesc());
  
      container.addView(view,0);
      return view;
  }
  
  @Override
  public void destroyItem(@NonNull ViewGroup container, int position, 
   @NonNull Object object) {
      container.removeView((View)object);
  }
  </code></pre>
  
  <p>HERE IS MY item.xml CODE :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:gravity="center_vertical"&gt;
  
  &lt;androidx.cardview.widget.CardView
      android:id="@+id/cardViewLogin"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      app:cardCornerRadius="20dp"
      android:layout_margin="8dp"
      android:clickable="true"
      android:focusable="true"
      android:foreground="?android:attr/selectableItemBackground"&gt;
  
      &lt;RelativeLayout
          android:layout_width="match_parent"
          android:layout_height="400dp"&gt;
  
          &lt;ImageView
              android:id="@+id/image"
              android:layout_width="match_parent"
              android:src="@drawable/hourglass"
              android:layout_height="200dp"
              android:scaleType="centerInside"
              android:layout_margin="10dp"/&gt;
  
          &lt;TextView
              android:id="@+id/title"
              android:layout_centerHorizontal="true"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_below="@+id/image"
              android:layout_marginTop="10dp"
              android:layout_marginStart="16dp"
              android:text="Title"
              android:textSize="16sp"/&gt;
  
          &lt;View
              android:id="@+id/separator"
              android:layout_width="match_parent"
              android:layout_height="1dp"
              android:background="@color/cardview_shadow_start_color"
              android:layout_margin="10dp"
              android:layout_below="@+id/title"/&gt;
  
          &lt;TextView
              android:id="@+id/desc"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_below="@+id/separator"
              android:layout_marginTop="3dp"
              android:layout_marginStart="16dp"
              android:layout_marginEnd="16dp"
              android:layout_marginBottom="20dp"
              android:maxLines="3"
              android:drawablePadding="10dp"
              android:ellipsize="end"
              android:text="Description"
              android:textSize="16sp"/&gt;
  
      &lt;/RelativeLayout&gt;
  &lt;/androidx.cardview.widget.CardView&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>HERE IS MY XML ACTIVITY LAYOUT CODE :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout 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=".UserLoginActivity"&gt;
  
  &lt;androidx.viewpager.widget.ViewPager
      android:id="@+id/view_pager"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:foregroundGravity="center"
      android:layout_gravity="center"
      android:overScrollMode="never"
      android:clipToPadding="false"&gt;
  
  &lt;/androidx.viewpager.widget.ViewPager&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>