Android SimpleAdapter 的list刷新问题。

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<HashMap<String, Object>> data = new ArrayList<HashMap<String, Object>>();//数据库中的数据
for(User u:users)//按照 HashMap的格式将数据库中的数据逐个逐个放进data中
        {
            HashMap<String,Object>item=new HashMap<String,Object>();
            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显示所有数据

你可能感兴趣的:(android)