Android的ListView控件在它的行可点击的项目会导致问题不断滚动 [英] Android ListView with clickable items in it's rows causes problems continuing scrolling

查看:207
本文介绍了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和切换按钮作出反应的点击,所以我实现了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启动活动的项目!好吧,我说,我只是做了RelativeLayout的捧在中间还有使用相同的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.

EXCEPT!现在,当我滚动列表,我不能只是再丢继续滚动。这会导致滚动停止,我要扔一次得到它去了。看来的onclick - 啄导致一扔运动是PTED为龙头什么的(它不会触发内的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.

所以,我怎么能确定名单不断滚动,并且仍然可以点击切换按钮,列表项和ImageView的?我一直被困在这个一整天,它让我头疼:(

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:

<一个href="http://stackoverflow.com/questions/1821871/android-how-to-fire-onlistitemclick-in-listactivity-with-buttons-in-list">How火onListItemClick在Listactivity与列表按钮?

codeFusionMobile提到设置安卓descendantFocusability 列表布局blocksDescendants,财产所以我尝试这样做。一切都按预期工作现在。滚动的作品, onListitemClicked 的作品,点击切换按钮的作品,点击的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天全站免登陆