行中带有可点击项目的 Android ListView 会导致继续滚动出现问题 [英] Android ListView with clickable items in it's rows causes problems continuing scrolling

查看:23
本文介绍了行中带有可点击项目的 Android ListView 会导致继续滚动出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在互联网上搜索了几个小时以寻找答案,但似乎找不到任何能够解决此问题的人.

I've been trawling the internet looking for an answer for several hours, but I can't seem to find anyone who has been able to solve this.

我有一个使用自定义适配器的列表视图.一行看起来像这样

I've got a listview which uses a custom adapter. A row looks like this

列表由数组填充.一切正常.

The list is filled by an array. Everything works great.

现在,我希望 ImageView 和 ToggleButton 对点击做出反应,所以我在我的适配器中实现了 OnClickListener,将项目放在每个视图的标签中,然后我将它们的 onclicklistener 设置为这个.

Now, I want the ImageView and the ToggleButton to react to clicks, so I implement the OnClickListener in my adapter, put the items position in each view's tag, and then I set their onclicklistener to this.

效果很好,除了现在我不能使用 onListItemClick 来启动项目的活动!好的,我说,我只是让相对布局在中间放置文本使用相同的 onclicklistener.效果很好.一切都是可点击的,生活是美好的.

Works great, except now I can't use the onListItemClick for starting an activity for the item! OK, I say, I just make the relativelayout holding the text in the middle there use the same onclicklistener. Works great. Everything is clickable, and life is good.

除了!现在,当我滚动列表时,我无法通过再次甩动来继续"滚动.这会导致滚动停止,我必须再次甩动才能让它再次运行.似乎 onclick-thingy 导致投掷动作被解释为点击或其他东西(它不会触发 onClick 内的逻辑).

EXCEPT! Now, when I scroll the list, I cannot "continue" the scroll by just flinging again. This causes the scrolling to stop, and I have to fling once more to get it going again. It seems the onclick-thingy causes the fling-motion to be interpreted as a tap or something (it does not trigger the logic within onClick).

我知道只需转到我的 HTC Hero 上的电话列表即可实现这一点,该列表具有我想要的应用程序的布局和行为类型.这个应用程序甚至似乎有 onItemClickListener 工作.

I know that this is possible by just going to the phone list on my HTC Hero, which has exactly the kind of layout and behaviour I want from my app. This app even seems to have the onItemClickListener working.

那么我怎样才能确保列表不断滚动,并且仍然能够点击切换按钮、列表项和图像视图?我一整天都被困在这个问题上,这让我很头疼:(

So how can I make sure the list keeps scrolling, and still be able to click the togglebutton, listitem and the imageview? I've been stuck on this all day, and it's giving me a headache :(

推荐答案

回家前的另一个快速搜索,我发现了这个:

Another quick search before I go home, and I came across this:

如何在 Listactivity 中触发 onListItemClick列表中的按钮?

CodeFusionMobile 提到将列表布局的 android:descendantFocusability 属性设置为 "blocksDescendants",所以我尝试这样做.现在一切都按预期工作.滚动作品,onListitemClicked作品,点击ToggleButton作品,点击ImageView作品.

CodeFusionMobile mentions setting the android:descendantFocusability property of the list layout to "blocksDescendants", and so I tried doing that. Everything works as expected now. Scrolling works, onListitemClicked works, clicking the ToggleButton works, clicking the ImageView works.

只是为了说清楚...在父 RelativeLayout 中,就在 row.xml 的顶部,我添加了

Just to make it clear... In the parent RelativeLayout, right at the top of the row.xml, I added

android:descendantFocusability="blocksDescendants"

这篇关于行中带有可点击项目的 Android ListView 会导致继续滚动出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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