2016-09-29 112 views
0

我有一個listFragmentViewPager裏面。問題在於列表OnItemSelected事件未被解僱。我可以聽到被點擊的項目的反饋聲音,但事件不會被執行。我已經嘗試設置android:descendantFocusability="blocksDescendants"但它沒有幫助。ListPragment裏面ViewPager onItemSelected沒有射擊

之前,我曾經有一個RecyclerView邏輯(使用Android Studio模板完成),它工作,但我想改變,因爲它看起來很混亂。

我這裏面activity_main.xml

<it.grsrl.rdd.redeye.Tools.CustomViewPager 
    android:id="@+id/container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

這是fragment_list.xml

<ListView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/listview_asset_list" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"/> 

這是簡單item_list.xml

<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="wrap_content" 
    android:padding="10dp"> 

    <RelativeLayout> 
     <ImageView /> 
     <TextView/> 
     <TextView /> 
     <TextView /> 
    </RelativeLayout> 

</FrameLayout> 

我做了一個試驗:我註冊了我的自定義適配器 一個OnClickListener裏面getView方法和視圖正在接收點擊。那麼,誰在吃我的點擊事件?

任何幫助?

+0

事情很少onListItemClick,並試圖覆蓋ViewGroup.onInterceptTouchEvent(MotionEvent EV)?並嘗試使item_list.xml進一步顯示focusable =「false」,clickable =「false」和focusableInTouchMode =「false」。你在哪裏使用了這個android:descendantFocusability =「blocksDescendants」?,它應該用於item_list.xml中的framelayout –

+0

我已經按照你所說的設置了一切,但它不會改變任何東西。我不知道如何重寫onInterceptTouchEvent – theBugger

回答

0

我錯過了ListFragment已經提供了一個可覆蓋的onListItemClick方法。我是這樣設定的聽衆在onViewCreated()

getListView().setOnItemSelectedListener() 

但最終這會靜默失敗。

所以,我只需要重寫我的ListFragment

@Override 
    public void onListItemClick(ListView l, View v, int position, long id) { 
     super.onListItemClick(l, v, position, id); 
      Item itm = mListener.onAssetClick(l.getItemAtPosition) 
     } 
    }