3
19
2013
18

关于Android ListView无法触发ItemClick事件的问题

由于在ListView的item中加入了按钮导致了无法触发ListView的ItemClick事件,在网上搜罗了下,找到了原因和解决办法:

如果自定义的ListViewItem中有Button或者Checkable的子类控件的话,那么默认focus是交给了子控件,而ListView的Item能被选中的基础是它能获取Focus,也就是说我们可以通过将ListView中Item中包含的所有控件的focusable属性设置为false,这样的话ListView的Item自动获得了Focus的权限,也就可以被选中了,也就会响应onItemClickListener中的onItemClick()方法,然而将ListView的Item Layout的子控件focusable属性设置为false有点繁琐,其实还可以通过对Item Layout的根控件设置其android:descendantFocusability=”blocksDescendant”即可(子孙的Focus能力).

 

上面解决了如何让ItemClick事件生效,但是问题又来了,我尝试着给Item中的按钮添加事件监听,但是似乎没地方给它加监听呢,看来得在写篇文章探讨下了。

参考:

http://blog.sina.com.cn/s/blog_8401d40201011e3t.html

 

Category: Android | Tags: Android ListView | Read Count: 6345
Avatar_small
لی ویوسوہ ہو یار 说:
2021年5月29日 16:03

Hello I am so delighted I located your blog, I really located you by mistake, while I was watching on google for something else, Anyways I am here now and could just like to say thank for a tremendous post and a all round entertaining website. Please do keep up the great work. click here

Avatar_small
لی ویوسوہ ہو یار 说:
2021年6月01日 19:20

I can’t believe focusing long enough to research; much less write this kind of article. You’ve outdone yourself with this material without a doubt. It is one of the greatest contents. hair transplant singapore

Avatar_small
لی ویوسوہ ہو یار 说:
2021年6月11日 13:34 Your work is truly appreciated round the clock and the globe. It is incredibly a comprehensive and helpful blog. brutal force supplement
Avatar_small
لی ویوسوہ ہو یار 说:
2021年6月18日 00:30

I am happy to find this post very useful for me, as it contains lot of information. I always prefer to read the quality content and this thing I found in you post. Thanks for sharing. 에볼루션카지노

Avatar_small
seo 说:
2021年6月18日 19:38

I was reading some of your content on this website and I conceive this internet site is really informative ! Keep on putting up. find out about daceasy

Avatar_small
movies123 说:
2021年6月30日 19:43

s reading some of your content on this website and I concei

Avatar_small
soaptoday 说:
2021年6月30日 20:29

as reading some of your content on this website and I conceive t

Avatar_small
visit here 说:
2021年6月30日 21:15

g some of your content on this website and I c

Avatar_small
Pancake Bunny 100X 说:
2021年7月04日 16:49

reading some of your content on this website and I co

Avatar_small
maaz 说:
2021年7月06日 18:34

There are particular dissertation websites that are online via the internet once you reach evidently published as part of your world wide web page. 더킹카지노

Avatar_small
123movie 说:
2021年7月29日 14:36

re particular dissertation websites that are online via the internet once you reach evidently published as part of your world wide web

Avatar_small
jackjohnny 说:
2021年9月06日 22:53

hello!! Very interesting discussion glad that I came across such informative post. Keep up the good work friend. Glad to be part of your net community. water based PU

Avatar_small
jackjohnny 说:
2021年9月09日 17:49

I admire this article for the well-researched content and excellent wording. I got so involved in this material that I couldn’t stop reading. I am impressed with your work and skill. Thank you so much. Business

Avatar_small
jackjohnny 说:
2021年9月14日 23:00

Cool stuff you have got and you keep update all of us. <a href="https://ibiza55.com/article/%e0%b9%84%e0%b8%ae%e0%b9%82%e0%b8%a5%e0%b8%ad%e0%b8%ad%e0%b8%99%e0%b9%84%e0%b8%a5%e0%b8%99%e0%b9%8c/">บาคาร่า"</a>

Avatar_small
jack 说:
2021年10月04日 23:36

A very awesome blog post. We are really grateful for your blog post. You will find a lot of approaches after visiting your post. voyance serieuse telephone

Avatar_small
link 说:
2021年10月13日 22:16

I admire this article for the well-researched content and excellent wording. I got so involved in this material that I couldn’t stop reading. I am impressed with your work and skill. Thank you so much. North American Bancard Agent Program

Avatar_small
jack 说:
2022年3月31日 19:57

Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info. Golden Revive Plus

Avatar_small
cleaning services 说:
2022年5月18日 21:59

Let’s are up against it – any oven is actually through quite a lot. While various models experience self-cleaning alternate options, they don’t make a thorough sparkling. Our high quality house cleaners can get done the work from the self-cleaning oven thereafter some. We’re confident that we all can remove many of the residue and additionally grime within your valuable item of equipment.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com