我想添加一个新的条目到我的列表视图并刷新它仍然显示在列表视图中的旧条目。以前我是用ArrayAdapter我是能够通过使用无法刷新ListView与SimpleAdapter
adapter.notifyDataSetChanged();
添加新条目之后刷新但是我无法使用以上SimpleAdapter的代码。任何建议? 我已经尝试了几个解决方案,但迄今没有任何工作。
下面是我使用的是不添加条目代码:如果您beta3
方法真的是你的函数将新条目添加到您的ListView
void beta3 (String X, String Y){
//listview in the main activity
ListView POST = (ListView)findViewById(R.id.listView);
//list = new ArrayList<String>();
String data = bar.getText().toString();
String two= data.replace("X", "");
ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String, String>>();
HashMap<String,String> event = new HashMap<String, String>();
event.put(Config.TAG_one, X);
event.put(Config.TAG_two, two);
event.put(Config.TAG_three, Y);
list.add(event);
ListAdapter adapter = new SimpleAdapter(this, list, R.layout.list,
new String[]{Config.TAG_one, Config.TAG_two, Config.TAG_three},
new int[]{R.id.one, R.id.two, R.id.three});
POST.setAdapter(adapter);
}
好像的[本]重复(http://stackoverflow.com/questions/9733572/android-adding-extra-item-on-listview)。 你如何尝试将项目添加到列表? – gus27