ListView 中的 ViewPager 和 OnItemClickListener [英] ViewPager and OnItemClickListener in ListView

查看:14
本文介绍了ListView 中的 ViewPager 和 OnItemClickListener的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个滑动关闭列表视图适配器.我的基本方法是将列表项的视图包装为 ViewPager 中的第二个视图,并在 ViewPager 的项目更改侦听器中提供必要的回调.经过很多痛苦,我让 View 回收器按预期工作,并实现了 ViewHolder 和 ViewBinder 模式.我什至设法让 ListView 在滚动 ViewPager 时不接管触摸事件,而无需创建 ListView 的自定义子类(我可以从适配器中完成这一切).

I'm working on creating a swipe-to-dismiss list view adapter. My basic methodology is to wrap the list item's view as the second view in a ViewPager and provide the necessary callbacks in the item change listener of the ViewPager. Through much pain I've got the View recycler working as intended, as well as ViewHolder and ViewBinder patterns implemented. I even managed to keep the ListView from taking over the touch events while the ViewPager is being scrolled without having to make a custom subclass of ListView (I can do it all from the Adapter).

我遇到麻烦的地方是让选择器和 OnItemClickListener 工作.在查看 ListView 的源代码后,似乎通过覆盖 ViewPager 的 hasFocusable() 方法以始终返回 false(稍后我将从子视图中提取此值),这些东西应该已经被重新启用.不幸的是,这种情况并非如此.我已经尝试了 setDecendantFocusability() 解决方法,但我仍然卡住了.

Where I'm running into trouble is getting the selector and the OnItemClickListener to work. After looking at ListView's source it seemed that by overriding the ViewPager's hasFocusable() method to always return false (later on I'll pull this value from the child view) these things should have been reenabled. Unfortunately this is not the case. I've tried the setDecendantFocusability() workaround and I'm still stuck.

如果可能的话,我想避免扩展 ListView 以提供最大程度的模块化.出于类似的原因,我不想将选择器添加到 ViewPager 的背景中(如果开发人员更改了 ListView 的选择器,则不会反映出来).本质上,我希望使 ListView 和子视图之间的 ViewPager 代码透明.有什么想法吗?

I'd like to avoid having to extend ListView if possible to provide the greatest amount of modularity. For similar reasons I don't want to add the selector to the ViewPager's background (if the dev changes the ListView's selector this wouldn't be reflected). Essentially I'm looking to make the ViewPager code transparent between the ListView and child View. Any ideas?

推荐答案

你是说你把每一个list item都做成view pager,这样就可以实现滑动删除?如果是这样……不,不,这不是视图寻呼机的用途.首先很抱歉,它只是不打算用作列表中的项目.其次是视图之间的切换,而不是滑动删除.

You are saying that you are making each list item a view pager, so that you can implement swiping to delete? If so... no no, this is not what view pager is for. First sorry it is just not intended to be used as an item in a list. Second it is for switching between views, not swiping to delete.

很遗憾,我们没有示例代码来展示如何执行此操作,但您可以查看平台对通知窗格或最近的应用程序的实现以获得一些想法.

Unfortunately we don't have a sample code to show how to do this, but you can look at the platform's implementation of the notification pane or recent apps to get some ideas.

这篇关于ListView 中的 ViewPager 和 OnItemClickListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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