2016-09-29 115 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) 
     } 
    }