2017-08-17 189 views
0

我已經使用https://github.com/moondroid/CoverFlow實現了Coverflow ViewPager它運行良好,但OnClick事件不適用於適配器。我嘗試了很多,但沒有成功,任何人有任何想法呢?OnClick事件在coverflow中不起作用

我的代碼看起來像下面

適配器點擊收聽

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

適配器XML是

<?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> 

回答

0

在活動實施clicklistner和嘗試這個

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 
      } 
     }); 

還是我n適配器

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

我已經在CoverFlow上使用了這個OnClick,但是我想執行單擊TextView窗體適配器。 – Komal

+0

okey ..比你嘗試刪除setOnItemClickListener比單擊textview? –

+0

是的,我已經刪除了CoverFlow的setOnItemClickListener,並在Adapter中添加了OnClickListener。 – Komal