I have a ListView to display a list of data, which I need to get from a DB first - the loading happens in an AsyncTask.
Now I want to refresh my list as soon as the AsyncTask has finished loading - I am using this to call adapter.notifyDataSetChanged();
in my Activity, but the List doesnt refresh.
Full Code:
In OnCreate:
adapter = new SimpleAdapter(ShopSwitchActivity.this, listData,
android.R.layout.simple_list_item_2,
new String[] {"name", "address"},
new int[] {android.R.id.text1,
android.R.id.text2});
listView.setAdapter(adapter);
AsyncTask<String, Void, List<Map<String,String>>> task = new LoadList(ShopSwitchActivity.this).execute();
try {
listData = task.get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
After Task is completed:
@Override
public void onTaskCompleted() {
adapter.notifyDataSetChanged();
}
listData = task.get();
returns the expected Result, it´s just not shown in the List.
(There is no crash or anything and every line gets called)
What am I missing here?
EDIT: Working Code:
@Override
public void onTaskCompleted() {
adapter = new SimpleAdapter(ShopSwitchActivity.this, listData,
android.R.layout.simple_list_item_2,
new String[] {"name", "address"},
new int[] {android.R.id.text1,
android.R.id.text2});
listView.setAdapter(adapter);
}
instead of just
@Override
public void onTaskCompleted() {
adapter.notifyDataSetChanged();
}