androidonclickandroid-viewpageradaptercoverflow

OnClick event is not working in coverflow


I have implemented Coverflow ViewPager using https://github.com/moondroid/CoverFlow it is working good, but the OnClick event is not working from the adapter. I tried a lot but didn't get an succeed, Any one have any idea about it?

My code looks like below

Adapter click listener

viewHolder.txtBookNow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent mIntent = new Intent(activity,ActivityDetail.class);
                activity.startActivity(mIntent);
            }
        });

Adapter xml is

    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout 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"
        android:foreground="@drawable/cover_selector">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:id="@+id/image"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="fitXY"
                android:src="@mipmap/simple_banner" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_marginBottom="15dp"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/txtPackage"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center_horizontal"
                    android:text="Package"
                    android:textColor="#0288D1"
                    android:textSize="12sp"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/txtBookNow"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:layout_marginTop="5dp"
                    android:background="@drawable/rounded_corner"
                    android:padding="5dp"
                    android:text="Book Now"
                    android:textColor="#ffffff"
                    android:textSize="10sp"
                    android:textStyle="bold" />
            </LinearLayout>
        </RelativeLayout>
    </FrameLayout>

Solution

  • Implement clicklistner in your activity and try this

    mCoverFlow = (FeatureCoverFlow) findViewById(R.id.coverflow);
            mCoverFlow.setAdapter(mAdapter);
    
            mCoverFlow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    // Do what you want
                    // list.get(position).titleResId
                }
            });
    

    Or In Adapter

    holder.image.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    System.out.println("=============== " + mData.get(position).titleResId);
                }
            });