简体   繁体   English

Android:自定义视图未在ListView中提供辅助功能事件

[英]Android: Custom Views not giving accessibility events in a ListView

I have a ListView that has an adapter with custom views in it. 我有一个ListView,其中有一个带有自定义视图的适配器。 The custom view extends from RelativeLayout. 自定义视图从RelativeLayout扩展。

This view reports accessibility events from the text correctly if it is inside another View. 如果该视图在另一个视图内,则可以正确报告该文本的可访问性事件。 If I add it to a ListView or a ViewPager, all of the custom views no longer provide accessibility events when TalkBack is enabled. 如果我将其添加到ListView或ViewPager,则启用“话语提示”后,所有自定义视图将不再提供可访问性事件。

Why don't my custom views work correctly inside a ListView? 为什么我的自定义视图无法在ListView中正常工作?

It turns out that if you assign a click listener to your View that's in a ListView or a ViewPager , you stop the accessibility events from propagating to those children. 事实证明,如果将单击侦听器分配给ListViewViewPager中的View, ViewPager阻止可访问性事件传播到那些子级。

Long story short, use setOnItemSelectedListener instead of setOnClickListener . 长话短说,请使用setOnItemSelectedListener而不是setOnClickListener

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

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