I want to use the Progress Dailog in my application. I am facing one issue in doing it, after some RnD I came to know that it is not quite possible to create the progress Dialog I have the Activity Group Class for the TabHost in the application.
I have exactly the same scenario, I have the TabHost in my application and an ActivityGroup Class that has the TabHost Classes. So, when I try to create the Progress Dialog for the Class that is in the Activity Group Class I cannot create it. But if I try to create the Progress Dialog for the Class that is not in the Activity Group I can create it with no issues.
Is there any solutions now?
I think the problem is with context of the progress dialog
Try giving the context of the dialog as getParent()
ProgressDialog.show(getParent(), " Loading...", "Please wait...", true, false);
Related
how can I add a new dialog with new layout on the currently running activity without making changes to the layout file of currently running activity. I cannot add a new activity as the old activity should remain active while the new dialog is displayed.
Here is a small snippet to get started on creating a Dialog and applying a layout file to it.
// create an instance of Dialog
Dialog dialog= new Dialog(c, R.style.CustDialog);
//inflate a layout
LayoutInflater inflater = this.getLayoutInflater();
View root = inflater.inflate(R.layout.custom_alert, null);
// set the layout for the Dialog
dialog.setContentView(root);
If you read the Dialog Docs it gives the different methods you can use.
Note the docs say
The Dialog class is the base class for dialogs, but you should avoid instantiating Dialog directly. Instead, use one of the following subclasses:
So for this reason you may want to look at AlertDialog which you can find plenty of examples of on SO or the Google.
This answer gives an example of creating a custom Dialog class.
I want to show an AlertDialog inside an AsyncTask inside a Fragment, but just so that the AlertDialog is inside that Fragment, and not "blocking" the whole application, so that I can go through my tabs and on one fragment there is a AlertDialog blocking that Fragment.
progressDialog = ProgressDialog.show(getActivity(), "Please wait...", "Fetching data", true);
ProgressDialogs are generally frowned upon by the Android Design Guidelines and in your case they are definitely problematic due to their modal nature. It would be preferable to include a ProgressBar component in each of your fragments and show / hide (from your async task).
http://www.yogeshblogspot.com/android-progress-bar-indeterminate/
I've searched everywhere and I can't find a solution to this problem.
Basically I have a login screen and I'm trying to get a progress spinner to show up while it's logging in to the server (via a thread), and then dismiss it after the login is successful. It has to work while changing orientations.
I am using DialogFragment with the Android compatibility package to make a progress bar (can't find any documentation on it, only for basic\alert dialog) because showDialog() is deprecated now. Right now I just show a custom message box as a login spinner.
In Summary:
How can I set up a Progress spinner with DialogFragment.
How can I dismiss it in another thread after orientation changes.
For showing a progress spinner, just override DialogFragment.onCreateDialog() in your dialog fragment like this (no need for overriding onCreateView()):
#Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
final ProgressDialog dialog = new ProgressDialog(getActivity());
//
dialog.setTitle(R.string.login_title);
dialog.setMessage(getString(R.string.login_message));
dialog.setIndeterminate(true);
dialog.setCancelable(false);
// etc...
return dialog;
}
As for dismissing that dialog fragment from somewhere else, you'll need to get a hold of FragmentManager (from inside your next FragmentActivity or Fragment) and call popBackStack() on it (if you don't do any other fragment transaction in the meantime).
If there's more steps/fragment transactions between your progress dialog fragment and the next activity, you'll probably need one of the other popBackStack(...) methods that take an ID or tag to pop everything up to your progress dialog fragment off the stack.
I know this is old question but I want to share much better solution for this
According to Android Development Protip:
"Stop using ProgressDialog,Inline indicators are your friend"
As Roman Nurik states:
This one's quick. Stop using ProgressDialog and other modal loading
indicators. They're extremely interruptive and annoying, especially
when:
You see one every time you switch tabs.
You can't Back out of them.
They say "Please wait." No thanks, I'd rather just uninstall.
Either show loading indicators inline with your content (e.g.
http://developer.android.com/training/animation/crossfade.html) or better yet, load small amounts of data in the
background so that you minimize the need to even show a loading
indicator.
More about progress & activity in the design guidelines.
Hi I have created an Activityname as ZBC. Where i have created Customized List view I am able to detect on click event using onItemClick() method of OnItemClickListener on list view. I want progress dialog to be displayed on click on ListView. I used the following code but I didnot get ProgressDialog
How to display progress dialog in onItemClick method
ProgressDialog.show(ABC.this, "", "Loading...", true);
But I didnot get ProgressDIalog
how to show progress dialog onitemclick, android
I used this in my application:
ProgressDialog.show(Main.this, null, getText(R.string.loading), true, true);
Giving null and not empty string as title, and it is cancelable.
Where did you set the onItemClickListener, some contect may be helpful? Maybe you are call it on wrong place.
I have a class that extends android.app.Dialog, the layout is done in an xml file, and the setup (button listeners, etc) is done on the onCreate method. My problem is that whenever the dialog is displayed, then dismissed, and displayed again, the Editable TextViews are still populated with the information that was displayed previously. What is the common way to clear these text fields? Remember - this is a separate class that extends Dialog - so there is no 'onDialogCreate' like Activity has.
Or, perhaps I am extending the wrong class? There is just a lot of processing being done, and do not want to have all the code in the main Activity. I would like it to be in a separate Class. I tried to extend AlertDialog, but it does not create the border like Dialog does. Any help would be great.
The dialog is shown via the Activity:
protected Dialog onCreateDialog(int id) {
switch(id){
case DIALOG_NEW_SAFE:
return(new NewSafeDialog(this));
default:
return(null);
}
}
onCreateDialog(..) caches the dialog which means the same instance is reused.
3 ways to fix the undesired behavior off my head:
Override onPrepareDialog(..), use findViewById(..) to get whatever you want to clear, clear it.
Don't rely on managed dialogs at all, do new NewSafeDialog(this).show() each time you want to show the dialog.
Add onCancelListener(..), onDismissListener(..) inside your custom dialog that would call a method to clear itself.
The good way to create a dialog is by using showDialog() as you did so don't change it.
The good and easy way to force deletion of a dialog in order to make your creation code recalled again is:
void removeDialog (int id)
So if you simply do the following, it's gonna work ;)
removeDialog(DIALOG_NEW_SAFE);
showDialog(DIALOG_NEW_SAFE);
Try clearing the text in the constructor of the NewSafeDialog i.e. your dialog class.