Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Loader on widget in xamarin android

Hi Everyone, I'm working on a weather app using Xamarin.Forms where I consume API and populate data in my widget in Xamarin.Android. Everything works fine but I have to show loader on widget when user click on update button in widget.

I was handling this using Visibility but it's not working properly. Is there anyone who can help me on this.

Any kind of help will be appreciated.

Best Answer

  • MohammedDastagirMohammedDastagir USMember ✭✭
    Accepted Answer

    I had to update my widget using below lines.

    (AppWidgetManager.GetInstance(context)).UpdateAppWidget(new ComponentName(context,               
                                       Java.Lang.Class.FromType(typeof(AppWidget)).Name), widgetView);
    

    Hope it helps.

Answers

  • jezhjezh Member, Xamarin Team Xamurai

    I was handling this using Visibility but it's not working properly.

    How did you hand this by using Visibility?Could you please post more details about this question,e,g, some code snippet?

  • MohammedDastagirMohammedDastagir USMember ✭✭

    @jezh Thanks for your reply! Kindly have a look at below code snippet.

    var widgetView = new RemoteViews(context.PackageName, Resource.Layout.Widget);
    widgetView.SetViewVisibility(Resource.Id.loaderLayout, ViewStates.Visible);
        widgetView.SetViewVisibility(Resource.Id.refreshLogo, ViewStates.Gone);
    
    //API Calling and data binding
    await SetTextViewText(widgetView, context);
    
    widgetView.SetViewVisibility(Resource.Id.loaderLayout, ViewStates.Gone);
        widgetView.SetViewVisibility(Resource.Id.refreshLogo, ViewStates.Visible);
    

    Widget is not updating that visibilities....

  • jezhjezh Member, Xamarin Team Xamurai

    Is there any log?

  • MohammedDastagirMohammedDastagir USMember ✭✭
    Accepted Answer

    I had to update my widget using below lines.

    (AppWidgetManager.GetInstance(context)).UpdateAppWidget(new ComponentName(context,               
                                       Java.Lang.Class.FromType(typeof(AppWidget)).Name), widgetView);
    

    Hope it helps.

Sign In or Register to comment.