Android - ListView 中的延迟点击 [英] Android - delayed clicks in ListView

查看:15
本文介绍了Android - ListView 中的延迟点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用中有以下结构:

I have the following structure in my app:

FragmentActivity 与 ViewPager 持有由 FragmentStatePagerAdapter 管理的多个片段,使用与 Android 2.1 的兼容包

FragmentActivity with ViewPager holding multiple fragments managed by FragmentStatePagerAdapter using compativility pack with Android 2.1

每个片段都包含 ListView.ListView 中的每个元素都有一个 LinearLayout,其中包含两个 TextViews 和一个 Button.LinearLayout 和按钮有 onClickListeners (分开).单击 LinearLayout 会启动另一个 Activity.我注意到点击行为非常不一致:有时会立即执行操作,但通常会延迟,有时无论我点击多少次都会忽略它.它变得更加奇怪,因为我可以点击并且只有在我开始滚动列表时才会执行该操作.我尝试了 setFocusable(false)setSelectable(true) 的各种组合,但似乎没有任何区别.有任何想法吗?我很乐意提供更多详细信息.

Each fragment contains ListView. Each element in the ListView has a LinearLayout with two TextViews and a Button. The LinearLayout and the button have onClickListeners (separate). Clicking on the LinearLayout starts another Activity. I noticed that the clicks behavior is very inconsistent: sometimes action is executed immediately but very often it is delayed and sometimes it's just ignored no matter how many times I tap. It gets even weirder because I can tap and the action will only be executed when I start scrolling the list. I tried various combinations of setFocusable(false) and setSelectable(true) but it seems to not make any difference. Any ideas? I'll be happy to provide more details.

推荐答案

如果有人想知道我是如何解决这个问题的.基本上我不得不简化我的布局.似乎当您有复杂的嵌套结构时,事件可能需要很长时间才能冒泡,如果您同时开始滚动列表,事件可能会触发错误的操作.我通过尽可能切换到 RelativeLayout 来修剪布局,这似乎有很大帮助

In case anybody wondered how I solved this. Basically I had to simplify my layouts. It seems that when you have complex nested structures events can take too long to bubble and if you start scrolling list at the same time event can trigger wrong action. I trimmed the layouts by switching to RelativeLayout as much as possible and that seemed to help a lot

这篇关于Android - ListView 中的延迟点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆