Android的 - 点击推迟ListView中Android、ListView

2023-09-05 02:15:49 作者:你是人间四月天

我在我的应用程序的结构如下:

I have the following structure in my app:

FragmentActivity与 ViewPager 持用compativility包与Android 2.1通过 FragmentStatePagerAdapter 管理​​的多个片段

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

每个片段包含的ListView 。在的ListView 每一个元素都有一个的LinearLayout 有两个 TextViews 按钮。该的LinearLayout 和按钮具有 onClickListeners (独立的)。点击的LinearLayout 启动另一个活动。我注意到的点击行为很不一致:有时候动作会立即执行,但它往往会被延迟,有时它只是忽略不管我有多少次点击。它会变得怪异,因为我可以挖掘,当我开始滚动列表中的动作才会被执行。我试过 setFocusable的各种组合(假) setSelectable(真),但它似乎没有任何区别。有任何想法吗?我会很乐意提供更多的细节。

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