Reputation: 43
I try to show a progress dialog upon showing a sliding drawer.
this is opening drawer event handler:
public void onDrawerOpened(View drawerView) {
progress = ProgressDialog.show(activity, "dialog title",
"dialog message", true);
openDrawer();
}
Inside openDrawer()
i call a function fillCommunityList()
that i need to show the progress dialog while its execution
fillCommunityList()
implementation is as the following:
private void fillCommunityList(){
new Thread(new Runnable() {
@Override
public void run() {
try {
// Here you should write your time consuming task...
UIManager manager = new UIManager(activity);
coms = manager.getCommunities();
progress.dismiss();
getOutTread = false;
} catch (Exception e) {
}
getOutTread = false;
}
}).start();
// to stop code till thread be finished
while(getOutTread){ }
SlidingMenuExpandableListAdapter adapter = new SlidingMenuExpandableListAdapter(this,
navDrawerItems, coms, mDrawerList);
mDrawerList.setAdapter(adapter);
}
Note: I put a thread just to make progress dialog works
My problem is the following two points:
1- progress dialog appears too late for sudden and then disappears
2- Thread takes alot of time in its execution (without thread fillCommunityList()
takes around 10 seconds but with a thread it takes more than a minute)
Note: manager.getCommunities()
has asyncTask in its implementation
Upvotes: 0
Views: 529
Reputation: 157487
The problem is the following line
while(getOutTread){ }
this is call busy waiting. The UI Thread is busy looping and can't, at the same time, draw/update the ProgressDialog
Upvotes: 1