Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Swipe/Pull to refresh

$
0
0

Hi,

I have seen a few threads on the swipe/pull to refresh for updating listviews. I have looked and it all looks very promising on iOS but less so on Android.

In my implementation I have created an attached property (a bit like what I used to do in Silverlight to stop me having to subclass the control) that I can attach to a TableView for my "detail" page and ListView for my "master" page. This would let my users swipe the list of data and also the item that has been navigated to run an ICommand to update my data from the webserver. This all seems to work cool on iOS, made a few custom renderers that read the attached properties and hook everything up nice with UIRefreshControls added to the UITableView for both forms controls if needed.

But on Android I would like to use the Android.Support.V4.Widget.SwipeRefreshLayout as this container control should be used to give my Android users the Android style swipe (I am thinking like in GMail with the snazzy colors!) This would stop me from having to worry about the renderer for the listview on Android being protected as really it not up to the listview but more the SwipeRefreshLayout to do its thing...

So I have created a refreshable view control that I can use in my Xaml document to wrap my original content that derives from Xamarin.Forms.ContentView, a custom render that creates the Android.Support.V4.Widget.SwipeRefreshLayout for my new content control and I can use my attached properties again on this control to trigger the refresh.

Sounds good, I get one Xaml document that has swipe for iOS and Android, for lists and data pages, but, it works fine on iOS but fails on Android as my custom renderer for the SwipeRefreshLayout is wrong. It throws an exception about its children. Anyone got any ideas on how to create the renderer for the SwipeRefreshLayout as once I have this I will open it up on Github for other people to use.

Cheers,

Simeon

Trace:
{System.InvalidOperationException: SetElement did not create the correct number of children
at Xamarin.Forms.Platform.Android.VisualElementPackager.SetModel (Xamarin.Forms.VisualElement oldModel, Xamarin.Forms.VisualElement newModel) [0x00000] in :0
at Xamarin.Forms.Platform.Android.VisualElementPackager.Load () [0x00000] in :0
at Xamarin.Forms.Platform.Android.VisualElementRenderer

1[Simeon.Common.UI.RefreshableView].SetPackager (Xamarin.Forms.Platform.Android.VisualElementPackager packager) [0x00000] in <filename unknown>:0 
  at Xamarin.Forms.Platform.Android.VisualElementRenderer
1[Simeon.Common.UI.RefreshableView].SetElement (Simeon.Common.UI.RefreshableView element) [0x00000] in :0
at Xamarin.Forms.Platform.Android.VisualElementRenderer
1[Simeon.Common.UI.RefreshableView].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in <filename unknown>:0 
  at Xamarin.Forms.Platform.Android.RendererFactory.GetRenderer (Xamarin.Forms.VisualElement view) [0x00000] in <filename unknown>:0 
  at Xamarin.Forms.Platform.Android.VisualElementPackager.AddChild (Xamarin.Forms.VisualElement view, IVisualElementRenderer oldRenderer, Xamarin.Forms.Platform.Android.RendererPool pool, Boolean sameChildren) [0x00000] in <filename unknown>:0 
  at Xamarin.Forms.Platform.Android.VisualElementPackager.SetModel (Xamarin.Forms.VisualElement oldModel, Xamarin.Forms.VisualElement newModel) [0x00000] in <filename unknown>:0 
  at Xamarin.Forms.Platform.Android.VisualElementPackager.Load () [0x00000] in <filename unknown>:0 
  at Xamarin.Forms.Platform.Android.VisualElementRenderer
1[Xamarin.Forms.Page].SetPackager (Xamarin.Forms.Platform.Android.VisualElementPackager packager) [0x00000] in :0
at Xamarin.Forms.Platform.Android.VisualElementRenderer
1[Xamarin.Forms.Page].SetElement (Xamarin.Forms.Page element) [0x00000] in <filename unknown>:0 
  at Xamarin.Forms.Platform.Android.VisualElementRenderer
1[Xamarin.Forms.Page].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in :0
at Xamarin.Forms.Platform.Android.RendererFactory.GetRenderer (Xamarin.Forms.VisualElement view) [0x00000] in :0
at Xamarin.Forms.Platform.Android.NavigationRenderer.SwitchContentAsync (Xamarin.Forms.Page view, Boolean animated, Boolean removed) [0x00000] in :0
at Xamarin.Forms.Platform.Android.NavigationRenderer.OnPushAsync (Xamarin.Forms.Page view, Boolean animated) [0x00000] in :0
at Xamarin.Forms.Platform.Android.NavigationRenderer.PushViewAsync (Xamarin.Forms.Page page, Boolean animated) [0x00000] in :0
at Xamarin.Forms.Platform.Android.NavigationRenderer.b__0 (Xamarin.Forms.Page p) [0x00000] in :0
at Xamarin.Forms.EnumerableExtensions.ForEach[Page] (IEnumerable1 enumeration, System.Action1 action) [0x00000] in :0
at Xamarin.Forms.Platform.Android.NavigationRenderer.OnElementChanged (Xamarin.Forms.Platform.Android.ElementChangedEventArgs
1 e) [0x00000] in <filename unknown>:0 
  at Xamarin.Forms.Platform.Android.VisualElementRenderer
1[Xamarin.Forms.NavigationPage].SetElement (Xamarin.Forms.NavigationPage element) [0x00000] in :0
at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[Xamarin.Forms.NavigationPage].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in :0
at Xamarin.Forms.Platform.Android.RendererFactory.GetRenderer (Xamarin.Forms.VisualElement view) [0x00000] in :0
at Xamarin.Forms.Platform.Android.MasterDetailContainer.set_ChildView (Xamarin.Forms.VisualElement value) [0x00000] in :0
at Xamarin.Forms.Platform.Android.MasterDetailRenderer.UpdateDetail () [0x00000] in :0
at Xamarin.Forms.Platform.Android.MasterDetailRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in :0
at Xamarin.Forms.Platform.Android.RendererFactory.GetRenderer (Xamarin.Forms.VisualElement view) [0x00000] in :0
at Xamarin.Forms.Platform.Android.Platform.AddChild (Xamarin.Forms.VisualElement view) [0x00000] in :0
at Xamarin.Forms.Platform.Android.Platform.SetPage (Xamarin.Forms.Page newRoot) [0x00000] in :0
at Xamarin.Forms.Platform.Android.AndroidActivity.SetPage (Xamarin.Forms.Page page) [0x00000] in :0
at Simeon.AdvancedServices.ApplicationHub.Droid.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x00021] in c:\Development\Framework II\Android\Simeon.AdvancedServices.ApplicationHub.Android\MainActivity.cs:27 }

Viewing all articles
Browse latest Browse all 58056

Trending Articles