How do i update listivew when async task is done. Below is the sample code but the listview isn’t updated.
class CallXML extends AsyncTask<Void, Void, Void> {
int gcid;
int scid;
public CallXML(int gid, int sid) {
// TODO Auto-generated constructor stub
gcid = gid;
scid = sid;
}
protected void onPreExecute() {
}
protected Void doInBackground(Void... arg0) {
// here goes the xml parsing....
}
return null;
}
protected void onPostExecute(String result) {
Log.e("TAG", "In postExecute");
Cursor cur3 = database2.query("Quote", qfield, null, null, null, null, null);
cur3.moveToFirst();
do {
quotesarray.add(cur3.getString(2));
} while (cur3.moveToNext());
if(cur3 != null){
cur3.close();
}
QList.post(new Runnable() {
public void run() {
mAdapter = new CustomAdapter();
mAdapter.notifyDataSetChanged();
QList.setAdapter(mAdapter);
}
});
if (helper2 != null) {
helper2.close();
}
if (database2 != null) {
database2.close();
}
}
}
EDIT:
Acutally onPostExecute is not executed why..This is the way I call asynctask new CallXML(gcid, scid).execute();
Also,
onPostExecuteis on the main thread so should not be doing database queries there. Instead, get data indoInBackgroundand return the final collection from there.onPostExecutecan be used for UI updates and updating your adapter with result collection.Edit: posting a runnable
is not required since you are in the main loop.