从项目儿童意见ListView和传播单击事件 [英] ListView and propagating click events from children views in the items

查看:80
本文介绍了从项目儿童意见ListView和传播单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义的项目一个ListView - 3 ImageViews和一个TextView。我需要打个电话 setItemsCanFocus(真),这样我就可以使ImageViews点击。我目前使用SimpleAdapter来填充视图。

I have a ListView with custom items - 3 ImageViews and a TextView. I have a call to setItemsCanFocus(true), so I can make the ImageViews clickable. I'm currently using SimpleAdapter to populate the View.

我想触发适配器视图的 onItemClick 事件被点击这些子视图之一时。该 onItemClickListener 接收到一个视图作为第二个参数,并可以用于确定哪些子视图被点击。坦率地说,我期待这是默认的行为,但它不是,很遗憾。

I'd like to trigger the AdapterView's onItemClick event when one of those subviews is clicked. The onItemClickListener receives a view as the second argument and that can be used to identify which subview was clicked. Frankly, I was expecting this to be the default behaviour but it isn't, unfortunately.

有什么办法来实现这一行为没有直截了当地破坏了封装(即创建一个适配器,持有引用视图)?

Is there any way to implement this behaviour without bluntly breaking encapsulation (i.e. creating an Adapter that holds a reference to its View)?

什么是处理从视图列表项的事件接受的方式?你如何从知道太多关于在ListView保持适配器?

What is the accepted way of dealing with events from views in list items? How do you keep the Adapter from knowing too much about the ListView?

推荐答案

不幸的是,你有个别儿童使用onItemClick()或的onClick()之间做出选择。然而这样做的一种方法是使每个项目可点击的顶层视图。

Unfortunately you have to choose between using onItemClick() or onClick() on individual children. One way to do it however is to make the top-level view of each item clickable.

这篇关于从项目儿童意见ListView和传播单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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