Android,SlidingPaneLayout和listView

a f*_*yer 5 android listview android-listview slidingpanelayout

ListView在我的SlidingPaneLayout主视图中使用了一个辅助视图.主视图是一个地图片段.该ListView充当菜单.问题是onItemClickedListener永远不会在ListView上调用.即使列表行也不会在出版时突出显示.似乎ListView无法获得焦点.

编辑:实际上,slidingPaneLayout.findFocus()显示android.widget.ListView.单击列表项仍然没有运气.

这是我的xml

<com.ziz.luke.custom_components.MySlidingPaneLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/slidingpanelayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >

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

    <ListView
        android:id="@+id/contactsList"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#00000000" >
    </ListView>

    <TextView
        android:id="@+id/android:empty"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:gravity="center_horizontal|center_vertical"
        android:text="@string/noContacts" />
</RelativeLayout>

<fragment
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.SupportMapFragment" />
</com.ziz.luke.custom_components.MySlidingPaneLayout>
Run Code Online (Sandbox Code Playgroud)

我怎么解决这个?

a f*_*yer 6

我找到了答案.我正在使用一个SlidingPaneLayout我最重要的子类

onInterceptTouchEvent(MotionEvent arg0)
Run Code Online (Sandbox Code Playgroud)

我试图做以下事情:

  • 使用按钮打开slidingPaneLayout.
  • 使用按钮关闭slidingPaneLayout.
  • 关闭使用滑动的slidingPaneLayout.
  • 阻止用户使用滑动打开slidingPaneLayout.

所以,我在我的子类中创建了一个名为shouldSwipe的布尔值,用于从over-ridden方法返回.

导致问题的实施是:

@Override
    public boolean onInterceptTouchEvent(MotionEvent arg0) {

        return shouldSwipe;
    }
Run Code Online (Sandbox Code Playgroud)

它会导致问题(shouldSwipe = true),因为它告诉系统触摸事件已被消耗并阻止它传播.

我用这个解决了这个问题:

@Override
    public boolean onInterceptTouchEvent(MotionEvent arg0) {
        // TODO Auto-generated method stub
        return shouldSwipe ?super.onInterceptTouchEvent(arg0):shouldSwipe;
    }
Run Code Online (Sandbox Code Playgroud)

而已.