Android SimpleAdapter 的list刷新问题。  

notifyDataSetChanged 来更新的,因为SimpleAdapter主要是用来创建静态的数据的列表,如果要实现动态更新数据,需要自己定义一个基于BaseAdapter的adapter,然后通过notifyDataSetChanged 来更新list。   If you look at the SimpleAdapter description it says it is "An easy adapter to map static data to views defined in an XML file." I've added the emphasis -- put simply, SimpleAdapater isn't built for use with data that changes; it handles static data only. If you can't use an ArrayAdapter because your data has more than a single bit of text, then you will either have to build your own custom ListAdapter, or put your data in a DB and use one of the CursorAdapters.
droid SimpleAdapter数据删除后界面更新,只需要加入代码(缺一不可):
data.remove(position);
simple.notifyDataSetChanged();

其中data和simple的定义如下:
final List> data = new ArrayList>();//数据库中的数据
for(User u:users)//按照 HashMap的格式将数据库中的数据逐个逐个放进data中
        {
            HashMapitem=new HashMap();
            item.put("id", String.valueOf(u.getId()));
            item.put("username", u.getUsername());
            item.put("password", u.getPassword());
            data.add(item);
        }
final SimpleAdapter simple=new SimpleAdapter(this, data, R.layout.listview, new String[]{"id","username"}, new int[]{R.id.id,R.id.username});//这个是为了在界面上用listView显示所有数据

更多相关文章

  1. Android之异步任务AsyncTask解析XML数据
  2. Android开发环境搭建常见问题(不定时更新)
  3. 细读《深入理解 Android(安卓)内核设计思想》(五)Binder 机制 [下]
  4. android 在子线程中如何把自定义对象传到handler中处理
  5. Android(安卓)返回上一个界面刷新数据
  6. HttpPost发送JSON数据中文乱码问题。
  7. Android中Shared Preferences、Files、Network、SQLite数据库编
  8. Android开发:界面布局的基本使用
  9. Android(安卓)studio APP开发 控制UI布局的方式,用代码书写UI界面

随机推荐

  1. Tiny210(Android)串口收发测试通过
  2. android菜单Tips
  3. TextView中ellipsize属性焦点异常处理
  4. 如何为香蕉派 banana pi BPI-M2编译Andro
  5. [android]Activity切换动画
  6. Android(安卓)编程设置 APN
  7. windows下载android源代码
  8. Android(安卓)入门 和 环境搭建
  9. android布局学习利器-Hierarchy Viewer
  10. Android(安卓)UI开发第二篇——多级列表(E