Android item长按删除功能
作者:黑-色-柳—丁 时间:2022-11-13 03:45:24
这个可以在Adapter里面写
一般写完之后都会调用
public void removeItem(int pos){
this.mDatas.remove(pos);
notifyItemRemoved(pos);
}
可是这样写的话,删除多次,会乱套,没有刷新
所以改这样子写
public void removeItem(int pos){
this.mDatas.remove(pos);
notifyItemRemoved(pos);
if(pos != mDatas.size()){ // 如果移除的是最后一个,忽略
notifyItemRangeChanged(pos, mDatas.size() - pos);
}
}
PS:下面看下android 长按删除listview的item
首先要继承OnItemLongClickListener
public class Set_Music extends ListActivity implements OnItemLongClickListener{
然后设置权限:
getListView().setOnItemLongClickListener(this);
重写方法
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
String str = list.get(arg2).get("name");
删掉长按的item
list.remove(arg2);
动态更新listview
adapter.notifyDataSetChanged();
以上所述是小编给大家介绍的Android item长按删除网站的支持!
来源:http://www.cnblogs.com/nuistlr/archive/2012/09/07/2675649.html
标签:android,item,长按删除
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
MyBatisPlus+Lombok实现分页功能的方法详解
2021-07-04 06:34:57
![](https://img.aspxhome.com/file/2023/3/85483_0s.png)
Java的二叉树排序以及遍历文件展示文本格式的文件树
2021-08-04 07:13:43
Java 中Flyway的使用详解
2022-04-11 03:38:54
![](https://img.aspxhome.com/file/2023/1/132451_0s.png)
基于java中两个对象属性的比较
2023-08-23 05:25:02
Java执行JS脚本工具
2022-04-07 08:00:16
![](https://img.aspxhome.com/file/2023/9/62159_0s.png)
使用java的HttpClient实现多线程并发
2022-09-19 20:35:55
微信支付仅能成功调用一次问题的解决方法(Android)
2021-07-27 10:40:17
![](https://img.aspxhome.com/file/2023/4/95994_0s.png)
springboot通过spel结合aop实现动态传参的案例
2022-01-26 01:00:47
![](https://img.aspxhome.com/file/2023/3/79883_0s.png)
SpringBoot 集成 Memcached的方法示例
2021-11-30 18:29:20
Spring Cloud Gateway 默认的filter功能和执行顺序介绍
2021-07-01 21:31:46
![](https://img.aspxhome.com/file/2023/0/85550_0s.png)
Java基础之Thymeleaf的简单使用
2023-08-24 19:00:22
![](https://img.aspxhome.com/file/2023/6/58086_0s.png)
android使用ExpandableListView控件实现小说目录效果的例子
2023-04-14 22:10:27
理解Java当中的回调机制(翻译)
2023-03-15 04:21:00
![](https://img.aspxhome.com/file/2023/0/89610_0s.png)
SpringMVC深入讲解文件的上传下载实现
2022-04-21 09:01:51
![](https://img.aspxhome.com/file/2023/8/71648_0s.png)
C#接口归纳总结实例详解
2021-08-18 16:55:54
C#中WebClient实现文件下载
2022-10-11 18:04:57
![](https://img.aspxhome.com/file/2023/5/77275_0s.png)
C# 函数返回多个值的方法详情
2022-01-05 05:47:11
Java反射机制(Reflection)浅析
2023-04-17 14:35:56
浅谈maven的jar包和war包区别 以及打包方法
2022-07-20 20:14:44
![](https://img.aspxhome.com/file/2023/8/63428_0s.png)
Android自定义View实现渐变色进度条
2022-11-25 08:27:17
![](https://img.aspxhome.com/file/2023/4/98694_0s.png)