如何激发onListItemClick在Listactivity与列表按钮?按钮、列表、onListItemClick、Listactivity

2023-09-11 11:17:21 作者:- 空了岛忘了潮 *

我有一个使用自定义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

希望它帮助;)

干杯