1
我試圖更新每個秒的ListView,所以我用的處理器和線程更新使用處理器和notifyDataSetChanged()更新列表視圖
我使用的notifyDataSetChanged();
重新加載listview
而不刷新活動。
但我的listview沒有更新。
我怎麼能反覆更新我的ListView不刷新活動
private class MessageTask extends AsyncTask<String, Void, String> {
private final HttpClient Client = new DefaultHttpClient();
@Override
protected String doInBackground(String... urls) {
String output = "";
for (String url : urls) {
try{
HttpGet httpget = new HttpGet(url);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
output = Client.execute(httpget, responseHandler);
}catch(Exception e){
Log.i("Animation", "Thread exception " + e);
}
}
return output;
}
protected void onPostExecute(String output) {
try {
JSONObject jObject= new JSONObject(output);
JSONArray menuObject = new JSONArray(jObject.getString("response"));
ArrayList<String> tExp=new ArrayList<String>();
//HashMap<String,ArrayList> map = new HashMap<String,ArrayList>();
for (int i = 0; i<menuObject.length(); i++)
{
tExp.add(menuObject.getJSONObject(i).getString("fk_username_c").toString()+" "+menuObject.getJSONObject(i).getString("message_c").toString());
}
adapter=new ArrayAdapter<String>(ChatActivity.this,android.R.layout.simple_list_item_1);
adapter.addAll(tExp);
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
adapter.setNotifyOnChange(isChangingConfigurations());
handler.postDelayed(this, 1000);
}
}, 1000);
listview.setAdapter(adapter);
} catch (JSONException e) {
Log.e("log_tag", "Error parsing data " + e.toString());
}
//intent.putExtra(extras);
}
}
這是什麼問題? – Raghunandan
我的listview沒有更新 – user12378334
這個代碼是用asynctsk寫的嗎? –