gpt4 book ai didi

Android、SlidingPaneLayout 和 listView

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:02:52 30 4
gpt4 key购买 nike

我在我的 SlidingPaneLayout 中使用 ListView 作为辅助 View 。主视图是一个 map fragment 。 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>

我该如何解决这个问题??

最佳答案

我找到了答案。我正在使用 SlidingPaneLayout 的子类,我在其中覆盖了

onInterceptTouchEvent(MotionEvent arg0)

我正在尝试执行以下操作:

  • 使用按钮打开 slidingPaneLayout。
  • 使用按钮关闭 slidingPaneLayout。
  • 使用滑动关闭 slidingPaneLayout。
  • 防止用户使用滑动打开 slidingPaneLayout。

因此,我在我的子类中创建了一个 bool 值,称为 shouldSwipe 以从重载方法返回。

导致问题的实现是:

@Override
public boolean onInterceptTouchEvent(MotionEvent arg0) {

return shouldSwipe;
}

无论何时 (shouldSwipe = true) 它都会引起问题,因为它告诉系统触摸事件已经被消耗并阻止它传播。

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

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

就是这样。

关于Android、SlidingPaneLayout 和 listView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17137582/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com