I have a listview and I’m loading dynamically items into it.
The problem is when I’m activating that activity. It takes too long, so I have to show some progress dialog while loading the UI.
I really don’t know how to do it, since doInBackground (If using Async task) doesn’t allow the developer to mess with the UI.
What should I do ?
Here is my UI load code :
LeagueTableRow leagueTableRow_data[] = new LeagueTableRow[]
{
new LeagueTableRow(1,R.drawable.logo,"aaa",12,9,3,14),
new LeagueTableRow(3,R.drawable.logo,"aaa",12,9,3,14),
new LeagueTableRow(4,R.drawable.logo,"aaa",12,9,3,14),
new LeagueTableRow(5,R.drawable.logo,"aaa",12,9,3,14),
new LeagueTableRow(2,R.drawable.logo,"aaa",12,9,3,14)
};
LeagueTableRowAdapter adapter = new LeagueTableRowAdapter(context,
R.layout.leaguetablecontent, leagueTableRow_data);
listViewLeagueTable = (ListView)findViewById(R.id.listViewLeagueTable);
View header = (View)getLayoutInflater().inflate(R.layout.leaguetableheader, null);
listViewLeagueTable.addHeaderView(header);
listViewLeagueTable.setAdapter(adapter);
If you set the emptyview using listView.setEmptyView . The view will show in the place of list until you do a setadapter on the list. So As soon as you do setAdapter the emptyview will disappear. You can pass Progressbar to the setEmptyview in your case to show the progressbar.
Edit:
Use Setadapter in OnPostExecute of the Asynctask.
OnPostExecute, OnPreExecute, OnProgressUpdate, OnCancelled all run on UI thread. If you still insist on ProgressDialog, then create dialog in OnPreExecute and dismiss it in OnpostExecute and OnCancelled of the Asynctask