private void loadItem(Activity activity, final String item_id) {
ProgressDialog myProgressDialog = new ProgressDialog(activity);
myProgressDialog.setTitle("Please Wait ...");
myProgressDialog.setMessage("Loading item ...");
myProgressDialog.setIndeterminate(true);
myProgressDialog.setCancelable(true);
final ItemDownload item_download = new ItemDownload(activity,
myProgressDialog) {
public Vector downloadCall(SmartFmLookup lookup) {
return lookup.item(item_id);
}
};
myProgressDialog.setButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
item_download.interrupt();
}
});
OnCancelListener ocl = new OnCancelListener() {
public void onCancel(DialogInterface arg0) {
item_download.interrupt();
}
};
myProgressDialog.setOnCancelListener(ocl);
myProgressDialog.show();
item_download.start();
}
I've even managed to support user cancellation. All good; however I have a more complex situation where the progress dialog is supposed to be displayed after hitting a menu button, and then replaced with another dialog that shows the results of the process; which is followed by a second progress dialog. In this case the first progress dialog never appears but the result dialog and second progress dialog do. I've tried removing all the other dialogs, but the initial progress dialog still never shows up - it gets stuck on the clicked menu button (see image).
Here's the code with subsequent dialogs stripped out:
public boolean onOptionsItemSelected(MenuItem menu_item) {
switch (menu_item.getItemId()) {
case ADD_TO_LIST_ID: {
// send command to add to list - need spinner?
final ProgressDialog myOtherProgressDialog = new ProgressDialog(
this);
myOtherProgressDialog.setTitle("Please Wait ...");
myOtherProgressDialog.setMessage("Adding item to study list ...");
myOtherProgressDialog.setIndeterminate(true);
myOtherProgressDialog.setCancelable(true);
// TODO spinner not showing for some reason ...
final Thread add = new Thread() {
public void run() {
AddItemResult add_item_result = addItemToList(
Main.default_study_list_id,
(String) item.item_node.atts.get("id"));
}
};
myOtherProgressDialog.setButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
add.interrupt();
}
});
OnCancelListener ocl = new OnCancelListener() {
public void onCancel(DialogInterface arg0) {
add.interrupt();
}
};
myOtherProgressDialog.setOnCancelListener(ocl);
myOtherProgressDialog.show();
add.run();
break;
}
}
return super.onOptionsItemSelected(menu_item);
}
I think the solution must require programmatic closing of the menu popup. I did find this post on how to open it. I was hoping to use that to open the menu bar at the beginning of my app, but calling that from the OnCreate method causes this error:
android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
However it seems I can use something similar to close the menu panel:
public void closeMenu(){
this.getWindow().closePanel(Window.FEATURE_OPTIONS_PANEL);
}
However, even after shutting the open menu panel, I still don't get to see the progress dialog.
Ah, found the problem, I was calling add.run() instead of add.start, so the new Thread was never spawned. Duh!!!
1 comment:
Hello
sorry can not help you, but I think you can help me I looked like doing that kind of menu and have not found how.
how I can make the item be covering the two spaces of the other items.
thank you very much, I hope you can help me.
Post a Comment