简体   繁体   English

Android:recyclerview如何实现setMultiChoiceListener?

[英]Android: recyclerview How to implemente setMultiChoiceListener?

I have a recyclerview and I want to implement a setMultiChoiceListener . 我有一个recyclerview ,我想实现setMultiChoiceListener Why is there no such function in the recyclerview ? 为什么在recyclerview没有这样的功能?

I do not want a simple longclick because the longclick executes the method only when the finger is no longer on the screen, while the set multichoice it performs the function after 1 second even if the finger is still on the screen 我不需要简单的longclick因为longclick仅在手指不再在屏幕上时才执行该方法,而set multichoice会在1秒后执行功能,即使手指仍在屏幕上也是如此

I think there is no multi choice listener because the RecylerView is designed that way , it recycles the layout items that are no longer visible and recreates them when needed. 我认为没有多选侦听器,因为RecylerView是按这种方式设计的,它可以回收不再可见的布局项目,并在需要时重新创建它们。

As a workaround you could do the following : 作为解决方法,您可以执行以下操作:

1.include a radio button that shows the
  selected state in the recyclerview item when clicked
2.In the adapter have an list of your choosing (eg. ArrayList) 
  that contains your selected objects (add/remove them when selected/deselected)
3.In the adapter you can make a method (eg. getSelectedItems()) that will 
  return that list.

If you provide what have you tried so far I will help you with the code 如果您提供到目前为止已尝试的内容,我将为您提供代码帮助

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

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