2014-09-25 52 views
0

我在自定義SlidingPaneLayout中有swipelistview。這是滑塊定義。SlidingPaneLayout中的SwipeListView不會攔截項目單擊事件

<com.tab.mobile.utilities.CustomSlider 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/slidingPanel" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<FrameLayout 
android:id="@+id/leftPane" 
android:layout_width="320dp" 
android:layout_height="match_parent" 
android:visibility="gone"/> 

<FrameLayout 
android:id="@+id/rightPane" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:layout_gravity="top" /> 

</com.tab.mobile.utilities.CustomSlider> 

這裏是滑塊類定義。

public class CustomSlider extends SlidingPaneLayout { 
    private boolean canSlide; 
    private int orientation; 

    private static final String TAG_NAME = "SlidingPaneLayout"; 

    public CustomSlider (Context context) { 
     super(context); 
    } 

    public CustomSlider (Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    public void setOrientation(int orientation) { 
     this.orientation = orientation; 
    } 

    @Override 
    public boolean onInterceptTouchEvent(MotionEvent event) { 
     Log.i(TAG_NAME, "intercepting touch event"); 

     return !canSlide ? super.onInterceptTouchEvent(event) : canSlide; 
    } 


    @Override 
    public boolean onTouchEvent(MotionEvent event) { 
     if(!canSlide) { 
      getChildAt(1).dispatchTouchEvent(event); 
      return true; 
     } 
     return super.onTouchEvent(event); 
    } 

    @Override 
    public boolean performClick() { 
     return super.performClick(); 
    } 

    public void setCanSlide(boolean canSlide) { 
     this.canSlide = canSlide; 
    } 
} 

而且在佈局XML的swipeListview初始化:

com.fortysevendeg.swipelistview.SwipeListView 
    android:id="@+id/enquiryListView" 
    android:layout_width="fill_parent" 
    android:layout_height="match_parent" 
    android:listSelector="#00000000" 
    swipe:swipeBackView="@+id/back" 
    swipe:swipeCloseAllItemsWhenMoveList="true" 
    swipe:swipeDrawableChecked="@drawable/choice_selected" 
    swipe:swipeDrawableUnchecked="@drawable/choice_unselected" 
    swipe:swipeFrontView="@+id/front" 
    swipe:swipeOpenOnLongPress="false" 
    /> 

在代碼中,我設置適配器swipeListview

enquiryView.setSwipeMode(SwipeListView.SWIPE_MODE_BOTH); 
enquiryView.setSwipeActionLeft(SwipeListView.SWIPE_ACTION_REVEAL); 
enquiryView.setSwipeActionRight(SwipeListView.SWIPE_ACTION_REVEAL); 
enquiryView.setOffsetLeft(value); 
enquiryView.setAnimationTime(50); // Animation time 
enquiryView.setSwipeOpenOnLongPress(false); 
enquiryView.setAdapter(adapter); 

enquiryView.setOnItemClickListener(listener); //this is not working. no events are coming to handler 

我需要兩個動作發生。

a。點擊列表項應鑽入其他屏幕

b。長按列表項應打電話openAnimate

我認爲滑動手勢不能使用,因爲它會重疊滑塊。我如何處理這個問題?有什麼我缺乏?

感謝, Renjith

回答

0

而不是使用setOnItemClickListener,你可以用SwipeListView自己setSwipeListViewListener。像這樣的東西應該適合你:

enquiryView 
     .setSwipeListViewListener(new BaseSwipeListViewListener() { 

      @Override 
      public void onOpened(int position, boolean toRight) { 
      } 

      @Override 
      public void onClosed(int position, boolean fromRight) { 
      } 

      @Override 
      public void onListChanged() { 
      } 

      @Override 
      public void onMove(int position, float x) { 
      } 

      @Override 
      public void onStartOpen(int position, int action, 
        boolean right) { 

      } 

      @Override 
      public void onStartClose(int position, boolean right) { 
      } 

      @Override 
      public void onClickFrontView(int position) { 
       // this is where you want to use click event on listview 
      } 

      @Override 
      public void onClickBackView(int position) { 
       // 
      } 

      @Override 
      public void onDismiss(int[] reverseSortedPositions) { 

      } 

     }); 

如果這不適合你讓我知道。

+0

我做到了!但是,長按觸發器onClickFrontView(int)方法 – Renjith 2014-09-25 11:18:36