how to display activity indicator upon button click while loading data from api.

Prakash7Prakash7 Member ✭✭

Need to display loading symbol while loading data from api upon button click.

Answers

  • MonkeyfeetMonkeyfeet USMember ✭✭

    That depends a lot on your page setup. The most straightforward way is to have a property called IsBusy in your viewmodel, then have an ActivityIndicator in your content somewhere with IsVisible, and IsRunning bound to IsBusy. Whenever you make a heavy call, set IsBusy = true, fire a PropertyChangedEvent to notify the view, and then set it back to false when you're done. You'd need to disable your controls whenever you do to make sure users aren't mashing buttons in the meantime (and that will be specific to what controls are on the page).

  • Prakash7Prakash7 Member ✭✭
    edited May 3

    Hi,
    Thanks a lot for replying.

    My code looks like this
    public async void OnLoginButtonClicked(object sender, EventArgs e)
    {
    indicator.isvisible=true;
    indicator.isrunning=true;// my activity indicator
    Myfunction();//This api calls function
    }

    Right now while the function is getting loaded I need to show activity indicator.
    Can you please your solution with this code as I am new to Xamarin forms.Thank you.

  • Gandhi_123Gandhi_123 Member ✭✭

    Hello @Prakash7

    I have same Problem like you. If you found any solutions then please help me.

    Thanks in advance

  • JohnHardmanJohnHardman GBUniversity mod
    edited October 11

    In the code above, Myfunction() is operating on the UI thread, so the ActivityIndicator cannot update as it needs the UI thread free. Have Myfunction() start a new task and do the work (not anything that touches the UI) in that task, making Myfunction() async and then having the code above await Myfunction().

Sign In or Register to comment.