java如何在加载其他项之前清除listview
我调用这个类是为了用下面的代码填充列表视图,问题是当调用它时,它会附加一个列表视图,我需要它来清除以前填充的数据。我该怎么做谢谢
protected String doInBackground(String... args) {
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("Products", Products));
JSONObject json = jParser.makeHttpRequest(url_all_products, "GET", params);
Log.d("All Products: ", json.toString());
try {
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
products = json.getJSONArray(TAG_PRODUCTS);
for (int i = 0; i < products.length(); i++) {
JSONObject c = products.getJSONObject(i);
String id = c.getString(TAG_PID);
String name = c.getString(TAG_NAME);
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_PID, id);
map.put(TAG_NAME, name);
productsList.add(map);
}
} else {}
} catch (JSONException e) {e.printStackTrace();}
return null;
}
protected void onPostExecute(String file_url) {
pDialog.dismiss();
runOnUiThread(new Runnable() {
public void run() {
ListAdapter adapter = new SimpleAdapter(
Concurency_main.this, productsList,
R.layout.list_item, new String[] { TAG_PID,
TAG_NAME},
new int[] { R.id.user_id, R.id.user_name});
setListAdapter(adapter);
}
});
}
# 1 楼答案
如果你添加到一个列表中,它会被追加。如果要删除所有,然后添加