how to display activity indicator

KavyaSKavyaS USMember ✭✭

I need to display an activity indicator while navigation or while calling an ApI...how to implement it?

Answers

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    I suggest to use https://github.com/aritchie/userdialogs

    the "Loading" method...

  • NMackayNMackay GBInsider, University mod

    @KavyaS

    Forms also has a built in Activity indicator.

    <StackLayout HeightRequest="40" VerticalOptions="End">
          <ActivityIndicator IsRunning="{Binding Busy}"
                             IsVisible="{Binding Busy}"
                              HeightRequest="40"
                              VerticalOptions="CenterAndExpand"
                              HorizontalOptions="CenterAndExpand">
            <ActivityIndicator.WidthRequest>
              <OnPlatform x:TypeArguments="x:Double" iOS="100" Android="100" WinPhone="400" />
            </ActivityIndicator.WidthRequest>
            <ActivityIndicator.Color>
              <OnPlatform x:TypeArguments="Color"
                          iOS="#2499CE" WinPhone="#2499CE" />
            </ActivityIndicator.Color>
          </ActivityIndicator>
        </StackLayout>
    
  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Personally I like the rg.plugins.popups package for popups. And you can make a "BusyPopup" to reuse for the needs you describe. That way you can have a semi-transparent busy indicator on top of your page to act as a barrier; keeping people from banging on buttons while the app is busying handling REST calls and so on.

  • RefkaBenmahmoudRefkaBenmahmoud USMember ✭✭✭

    @ClintStLaurent how you use it?

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    @RefkaBenmahmoud if you go to rg.plugin's github site you find some samples

  • AymancsAymancs USMember ✭✭

    @AlessandroCaliaro said:
    I suggest to use https://github.com/aritchie/userdialogs

    the "Loading" method...

    but how to display progress before calling Api and hide it after finishing calling Api
    I did the following
    UserDialogs.Instance.ShowLoading(); before calling api
    and
    UserDialogs.Instance.HideLoading(); after calling api

    but nothing happened, the action happened after clicked event has been finished. so if i removed this line "UserDialogs.Instance.HideLoading()" the progress will appear

    what shall i do ?!

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    you should post your code.

    Is it an async / await code?

    I usually use something like

    using (UserDialogs.Instance.Loading("wait...")) {
    
        // Do something 
    }
    
  • TamasMatraiTamasMatrai HUUniversity ✭✭

    @AlessandroCaliaro said:
    you should post your code.

    Is it an async / await code?

    I usually use something like

    using (UserDialogs.Instance.Loading("wait...")) {

      // Do something 
    

    }

    Does not work for me, it simply does not appear. Do you have any suggestions?

  • seanydaseanyda GBMember ✭✭✭✭✭

    @TamasMatrai said:

    @AlessandroCaliaro said:
    you should post your code.

    Is it an async / await code?

    I usually use something like

    using (UserDialogs.Instance.Loading("wait...")) {
    
        // Do something 
    }
    

    Does not work for me, it simply does not appear. Do you have any suggestions?

    Have you also installed the package in your iOS and Android projects? and have you added this line into your Droids MainActivity.cs?

    UserDialogs.Init(this);

  • TamasMatraiTamasMatrai HUUniversity ✭✭

    @seanyda said:

    @TamasMatrai said:

    @AlessandroCaliaro said:
    you should post your code.

    Is it an async / await code?

    I usually use something like

    using (UserDialogs.Instance.Loading("wait...")) {

      // Do something 
    

    }

    Does not work for me, it simply does not appear. Do you have any suggestions?

    Have you also installed the package in your iOS and Android projects? and have you added this line into your Droids MainActivity.cs?

    UserDialogs.Init(this);

    Thanks :) I forgot it!

  • Hi, someone who can tell me how to use Arc in Xamarin.Form, I get an error in MainActivity

    protected override void OnCreate(Bundle bundle)
    {
    TabLayoutResource = Resource.Layout.Tabbar;
    ToolbarResource = Resource.Layout.Toolbar;
    UserDialogs.Init(this);
    base.OnCreate(bundle);
    DevExpress.Mobile.Forms.Init();

            global::Xamarin.Forms.Forms.Init(this, bundle);
    
    
            LoadApplication(new App());
    
        }
    
  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    @VictorRangel.4469
    Please don't hijack other people's threads just because it kinda, sorta has a couple words that maybe sorta sounds like your question.

    Please start your own question.

  • kundtibrkundtibr Member ✭✭

    Hi i am using
    public interface IProgress
    {
    void Show(string message);
    void Hide();
    }

    [assembly:Dependency(typeof(Progress))]
    namespace MyDemo.Droid.DependencyServices
    {
    public class Progress : IProgress
    {
    public void Hide()
    {
    AndHUD.Shared.Dismiss();
    }

        public void Show(string message)
        {
            AndHUD.Shared.Show(Forms.Context, message);
        }
    }
    

    }

    and i use like that

        private  void Orders(IAuthorizationContext authContext)
        {
    
                    DependencyService.Get<IProgress>().Show(loading....);
                    DependencyService.Get<IProgress>().Hide();
        }
    

    but it not show the speeing wheel some time

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    @sarveshs What part of Don't hijack other people's threads posted right above where you posted - did you not understand? Maybe you are new to the internet or forums such as this so let me bring you up to speed: Doing that is considered very rude. Its the equivalent of jumping into a conversation other people are having and just taking it over for your own problems.

    Please start your own thread for your issue. Also, please use markdown to properly mark the code in your post so the site doesn't try to interpret it as something it should be rendering.

    FYI: If you read the documentation on ActivityIndicator you'll see it has to be raised from the Page currently being shown.

    @ClintStLaurent said:
    @VictorRangel.4469
    Please don't hijack other people's threads just because it kinda, sorta has a couple words that maybe sorta sounds like your question.

    Please start your own question.

  • kundtibrkundtibr Member ✭✭

    @ClintStLaurent sorry for that

  • lombardalombarda Member ✭✭

    Probably late on this but have been battling with the activity thing for a long time and finally got it to work as follows:
    Rather than using the standard Xamarin ActivityIndicator (which will also work) I installed Nuget Acr.UserDialogs and used the ShowLoading and HideLoading methods (just cleaner code for lazy me). The trick was to put my long running task into a Task that is not part of the UI thread and here is some code that works great in a shared project, but only fully tested with Android (You have to do an init in MainActivity.cs for Android - Nuget readme gives you all that):

    My job kicks off with the user trying to register and hitting the button. So I made the button event handler async:
    (Excuse my ignoring Xamarin and C# naming conventions, been programming for 35 years so old habits die hard)

        //New user registration
        private async void btn2Confirm(object sender, EventArgs e)
        {
    

    //Here I do some input validation first and bail out if needed prior to calling my web client interface that takes the time

    //Start the busy thingy
    UserDialogs.Instance.ShowLoading("Checking");

    //Call a Task that checks on a server for database entries
    await createNewUser();

    //when done, hide the thingy
    UserDialogs.Instance.HideLoading();

    The task will set a string (friend variable to all in the class) called msg if anything goes wrong in order for the user to be informed
    if (msg != "")
    await DisplayAlert("Error", msg, "OK");
    }

    //The task called is declared like this
    private async Task createNewUser()
    {
    await Task.Delay(250)
    .ContinueWith(task =>
    {
    try
    {

                    //Here I do my calls to my version of an API using JSON stuff, and this normally takes a few seconds. If anything goes wrong, a message goes into var msg and task is terminated
                }
                          catch (Exception ex)
                          {
                              msg = ex.Message;
                          }
            });
    }
    

    Hope it's useful. First time I posted something

Sign In or Register to comment.