I have a requirement where i have to show the status of the download on a DisplayAlert. But with changing text on it asynchronously.
How to achieve this?
DisplayAlert("Download Info", "Downloading.....", "Ok");
I want to show status like...
- Connected to server
- Downloading
- Download Complete
Here is a simple "Dynamic Alert" for Forms and
iOS
usingUIAlertController
andAndroid
using aDialogFragment
and aXamarin.Forms
dependency service:Dependency Interface:
iOS
IDynamicAlert
Dependency Implementation:Example Usage:
Output:
Android Version:
The android version consists of a couple of parts, a
DialogFragment
subclass and theIDynamicAlert
implementation that uses the customDialogFragment
.Android DialogFragment Subclass:
Android
IDynamicAlert
Dependency Implementation:Android Init / Usage:
When creating the
AlertDialog
in theDialogFragment
we need access to the currentActivity
and when usingXamarin.Forms
, that is normally theMainActivity
that is aFormsAppCompatActivity
subclass. Thus you will need to initialize theDynamicAlert.CurrentActivity
static property with thisActivity
in yourMainActivity.OnCreate
subclass:Example:
}
Android Output: