android - RecyclerView中 我长按一个Itme 然后所有的Item 出现一个删除的小图标 这个怎么实现
阿神
阿神 2017-04-18 09:15:17
0
2
705

现在的问题是我长按了图标 只是单个item出现了 删除的小图片 而不是所有的 请问要怎么实现长按一个item 所有的itme 项都出现删除的小图片?

阿神
阿神

闭关修行中......

reply all(2)
大家讲道理

In the data object collection in the Adapter, set a variable to indicate whether the current item status is to display the delete small icon or not. When long pressing a single item, change the value of the deletion status variable of all data in the collection, and use notifyItemRangeChanged (0, the number of all items - 1) to notify RecyclerView that the status of all items has changed, and then trigger a re- Call onBindViewHolder, and display the icon based on whether the item displays the delete icon status.

巴扎黑

The logic is written into bindView. When it needs to be changed, modify the flag value and notifyDataSetChanged

//伪代码如下
 public void onBindViewHolder(ViewHolder holder, int position){
        myIcon.setVisibility(showIcon ? View.VISIBLE : View.INVISIBLE);
    }
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template