Android Listview Not Updating After Calling Notifydatasetchanged()
I have a custom list adapter and get data to fill it via a Asynctask that gets data from a webserver. This all seems to work fine however when I call notifyDataSetChanged() the lis
Solution 1:
Try this..
Remove all below codes in OnCreate()
accountslist = newArrayList<Account>();
m_adapter = newMyListAdapter(this, R.layout.list_row_layout,
accountslist);
accounts.setAdapter(m_adapter);
Add that inside onPostExecute
like below
protectedvoidonPostExecute(String file_url) {
// dismiss the dialog after getting all products
pDialog.dismiss();
// updating UI from Background Thread
runOnUiThread(new Runnable() {
publicvoidrun() {
/**
* Updating parsed JSON data into ListView
* */
accountslist = new ArrayList<Account>();
for (int i = 0; i < productsList.size(); i++) {
Account list = new Account(
Integer.parseInt(productsList.get(i).get(
"ACCOUNTID")),
Integer.parseInt(productsList.get(i).get(
"BALANCE")));
accountslist.add(list);
}
m_adapter = new MyListAdapter(this, R.layout.list_row_layout, accountslist);
accounts.setAdapter(m_adapter);
}
});
}
Solution 2:
Not use notifyDataSetChanged();
in run()
but at the end.
Post a Comment for "Android Listview Not Updating After Calling Notifydatasetchanged()"