I'm using Azure Mobile Services to support my Android app and in this scenario, I'm trying to retrieve some database data using this method:
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
try {
final MobileServiceList<ActivityTable> result = activitiesTable.execute().get();
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
if (!(result.isEmpty())) {
for (ActivityTable item : result) {
final ActivityTable activity = new ActivityTable();
activity.setID(item.getId());
activity.setContent(item.getContent());
activity.setUserID(item.getUserID());
activity.setMedia(item.getMedia());
activity.setType((item.getType()));
UserTable user = GetUser(item.getUserID());
activity.setUser(user);
activities.add(activity);
}
//Populate ListView
PopulateNewsreel();
} else {
Log.e("test", "Error in Activity Loading 1");
}
}
});
} catch (Exception exception) {
Log.e("test","Error in Activity Loading 2");
Log.e("test",exception.toString());
}
return null;
}
}.execute();
And then I populate my listview using the retrieved data:
ListView newsreel = (ListView) getActivity().findViewById(R.id.newsreel_list);
NewsfeedAdapter adapter = new NewsfeedAdapter(getActivity(),R.layout.activity_newsfeed,activities);
newsreel.setAdapter(adapter);
However, the listview population is delayed and sometimes no data is shown in the listview but it takes time. After a delay of about 3 seconds, the data is populated, until then the listview populates the listview items with their placeholders. You get the idea.
How can I wait till the retrieval is completed before showing the view so that I can populate the listview?