简体   繁体   English

在列表视图行中添加多个可点击区域

[英]Add multiple clickable zones in a listview row

I want to implement a row for a listview with two click zones with some special requirements: 我想为具有两个特殊要求的两个单击区域的listview实现一行:

What I want to implement is something like: 我要实现的是这样的:

在此处输入图片说明

With the following click config: 使用以下单击配置:

  • The red zone links the user profile 红色区域链接用户个人资料
  • The blue zone links the item detail 蓝色区域链接项目详细信息
  • Clicks over the yellow zone are ignored 黄色区域的点击将被忽略
  • When clicking the blue zone all the row is selected (like with a background= ?attr/selectableItemBackground ) 单击蓝色区域时,所有行均被选中(例如,background = ?attr/selectableItemBackground

I have tried several configs but I do not get all the points: 我已经尝试了几个配置,但我没有得到所有要点:

Config A: Add a clicklistener over the blue container and another over the red container, works nice but the full row selected effect when clicking the blue zone is missing. 配置A:在蓝色容器上方添加一个clicklistener,在红色容器上方添加一个clicklistener,效果很好,但是单击蓝色区域时缺少整行选择的效果。

Config B: Add a clickListener over the full row and another clicklistener over the red container, also works but the clicks over the yellow zone are not ignored. 配置B:在整行上添加一个clickListener,在红色容器上添加另一个clicklistener,也可以,但是不忽略黄色区域上的点击。

How can I accomplish that? 我该怎么做?

Note: Also tried to use the Config B with an empty click listener over the yellow container. 注意:还尝试将配置B与黄色容器上方的空单击侦听器一起使用。 But sounds weird to add a clickListener to ignore it, and my real view is more complex than that and I should add a lot of empty clicklisteners. 但是添加clickListener忽略它听起来很奇怪,而我的实际视图比这更复杂,因此我应该添加很多空的clicklistener。 The ideal behavior should be the blue container to propagate its click status to the rowView 理想的行为应该是将其点击状态传播到rowView的蓝色容器

So A works but you want to get rid the on pressed color ? 因此,A可以工作,但您想摆脱所按的颜色吗? If so add this in your ListView XML. 如果是这样,请将其添加到ListView XML中。

    <ListView
    android:cacheColorHint="#00000000"
    android:listSelector="@android:color/transparent"
    />

您必须实现一个具有两个子布局的布局,其中一个包含头像,另一个包含您的数据,而在适配器类中,您必须添加具有特定布局ID的标记,还必须为该布局添加OnClickListener,然后您单击具有标签的布局,然后基于该标签,您就可以在ListView Item中处理您的视图。

You can go with either A or B just with minor addition 只需少量添加即可使用AB

A :

Call listview method void setItemsCanFocus(false) so when you click on Blue part, whole row will get focus 调用listview方法void setItemsCanFocus(false)因此当您单击Blue部分时,整行将获得焦点

B : B

Override isEnabled() method in your custom or base adapter and return false for the Yellow part. 在您的自定义适配器或基本适配器中覆盖isEnabled()方法,并为Yellow部分返回false This will block click events to Yellow part 这会将点击事件阻止为黄色部分

I hope your error will fix. 希望您的错误能解决。

Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM