How to update SimpleAdapter in Android

后端 未结 5 1226
死守一世寂寞
死守一世寂寞 2020-12-19 04:06

Is it possible to update a SimpleAdapter? I have a list of data and a footer that says \"See Next Results\" When that list item is clicked I capture the event and get new d

5条回答
  •  太阳男子
    2020-12-19 04:48

    I was not able to get notifyDataSetChanged() to work on updating my SimpleAdapter, so instead I tried first removing all views that were attached to the parent layout using removeAllViews(), then adding the ListView, and that worked, allowing me to update the UI:

    LinearLayout results = (LinearLayout)findViewById(R.id.results);
    ListView lv = new ListView(this);
    ArrayList> list = new ArrayList>();
    SimpleAdapter adapter = new SimpleAdapter( this, list, R.layout.directory_row, 
                        new String[] { "name", "dept" }, new int[] { R.id.name, R.id.dept } );
    
    for (...) { 
        HashMap map = new HashMap();
        map.put("name", name);
        map.put("dept", dept);
        list.add(map);
    }
    
    lv.setAdapter(adapter);
    results.removeAllViews();     
    results.addView(lv);
    

提交回复
热议问题