如何激发onListItemClick在Listactivity与列表按钮? [英] How to fire onListItemClick in Listactivity with buttons in list?

查看:223
本文介绍了如何激发onListItemClick在Listactivity与列表按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用自定义ListAdapter生成列表视图一个简单的ListActivity。通常情况下,ListAdapter只想填补TextViews的意见,但现在我想提出一个按钮那里。

I have a simple ListActivity that uses a custom ListAdapter to generate the views in the list. Normally the ListAdapter would just fill the views with TextViews, but now I want to put a button there as well.

这是我的理解和经验,但是这将作为焦点的视图列表中的项目prevents onListItemClick的射击()在ListActivity列表​​项被点击时。还是按钮的功能通常在列表项,但除了按钮的东西是pressed,我想onListItemClick被触发。

It is my understanding and experience however that putting a focusable view in the list item prevents the firing of onListItemClick() in the ListActivity when the list item is clicked. The button still functions normally within the list item, but when something besides the button is pressed, I want onListItemClick to be triggered.

我怎样才能使这项工作?

How can I make this work?

推荐答案

我在 previous评论写的解决方案是setFocusable(假)上的ImageButton。

as I wrote in previous comment solution is to setFocusable(false) on ImageButton.

甚至还有的更好的解决方法尝试添加安卓descendantFocusability =blocksDescendants中的根布局列表元素。这将使点击onListItem可能并单独u能处理按钮或ImageButton的点击

There is even more elegant solution try to add android:descendantFocusability="blocksDescendants" in root layout of list element. That will make clicks onListItem possible and separately u can handle Button or ImageButton clicks

希望它帮助;)

干杯

这篇关于如何激发onListItemClick在Listactivity与列表按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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