我有一個佈局,它有edit_text按鈕和list_view我在編輯文本中輸入文本,併發送它與按鈕時,我點擊按鈕數據將顯示在list_view問題是數據只顯示當我點擊後退按鈕並再次打開list_view然後數據顯示。我有list_view刷新問題我想要當我發送數據list_view automaticaly更新並顯示數據這裏是list_view的代碼。android listview數據不刷新數據來自服務器
protected void showList() {
try {
JSONObject jsonObj = new JSONObject(myJSON);
peoples = jsonObj.getJSONArray(TAG_RESULTS);
for (int i = 0; i < peoples.length(); i++) {
JSONObject c = peoples.getJSONObject(i);
//String sender_email = c.getString(TAG_SENDER_EMAIL);
// String reciver_email = c.getString(TAG_RECIVER_EMAIL);
String data = c.getString(TAG_DATA);
// String email = c.getString(TAG_EMAIL);
// e1.setText(reciver_email);
HashMap<String, String> user_data = new HashMap<String, String>();
// persons.put(TAG_ID,id);
user_data.put(TAG_DATA, data);
// users.put(TAG_EMAIL,email);
personList.add(user_data);
}
ListAdapter adapter = new SimpleAdapter(
DataSendActivity.this, personList, R.layout.layout_chat,
new String[]{TAG_DATA},
new int[]{R.id.data}
);
list.setAdapter(adapter);
} catch (JSONException e) {
e.printStackTrace();
}
}
你嘗試過 'adapter.notifyDataSetChanged()' 您填寫您的名單後? – pooyan
沒有如何使用它?我是新的機器人請告訴我 –
看到我的答案。 – pooyan