【发布时间】:2023-03-22 14:11:01
【问题描述】:
我正在尝试向我的列表视图中添加一个新条目,并使用仍显示在列表视图中的旧条目刷新它。以前我使用的是 ArrayAdapter,我可以在使用
添加新条目后刷新它 adapter.notifyDataSetChanged();
但我无法将上面的代码与 SimpleAdapter 一起使用。有什么建议吗? 我已经尝试了几种解决方案,但到目前为止都没有奏效。
以下是我正在使用的代码,它没有添加条目:
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);
}
【问题讨论】:
-
似乎是 this 的副本。您如何尝试将项目添加到列表中?
标签: android listview simpleadapter