Ok, a small update: I downloaded the Xamarin example project from here. https://developer.xamarin.com/samples/xamarin-forms/customrenderers/viewcell/. Works really fine, but when I exchange the ListView with the SyncfusionListView, it crashes!
The stracktrace is in the attachment. Really disappointing right now, because we're nearly in the finished state of our app and I need to implement a custom recycable ViewCell for Ads so that they are not constantly reloaded everytime I scroll through the list...
Hello Dinesh,thank you for your reply.
Unfortunately that's not what I was looking for. My goal is to implement a CustomCell with a custom cellrenderer. In the provided example from you the view is already defined in the IncomingViewCell.xaml or OutgoingViewCell.xaml.
What I need to do is this: The cell is filled with a platform specific view (a NativeExpressAdView from Admob to be specific). I create this view on the platform level and this has to be shown in the listview.
With the Xamarin ListView a custom cell with a custom rendering works fine. With SyncFusion it crashes (see stacktrace in my former post). I need to use SyncFusion because of the SwipingFeatures.
Update: It seems that a SyncFusionListView can't handle an empty ViewCell and never goes down to the platform specific cellrenderer... is this true?
I'd appreciate any help with this!
Hi Dinesh,
thank you for your reply. Sadly I cannot load the View in the PCL project itself.
Also I don't use a viewcellrenderer, because it's not working with Syncfusion. I use a viewrenderer, because the Native Ads are giving me no other choice. I have to provide a NativeExpressAdView on each platform (android & iOS). That's why the renderer kicks in. The problem is: Each time the view is created (it's not reused, I did some breakpoints while scrolling) I'll create a new AdRequest which loads an ad. If the cell would be reused, I won't need to load an ad. But because the viewrenderer is always new created, when I scroll up or down the list, the ads are constantly loading new. That means kind of hickups in the app (blank list elements, which are filled, when the ad is loaded).
I know it's maybe hard to follow. But with in order to use native ads from Google, I have to implement a Viewrenderer which is always recreated (the typical Control == null check is always true). A better way for me would have been to create a CustomViewCellRender which is being reused. But I cannot implement one with Syncfusion Listview (with Xamarin Listview it works, try the example: https://github.com/xamarin/xamarin-forms-samples/tree/master/UserInterface/ListView/CustomCells).
So I come to the conclusion that Syncfusion ListView does not support viewcells with custom renderers on each platform right now, because it's not calling the platform specific cellrenderer or crashes (see stacktrace in second post), if you provide an empty ViewCell tag in xaml.
this.listView.ItemTemplate = new DataTemplate(typeof(ViewCellExt));
public class ViewCellExt : ViewCell
{
} |
public class ItemGeneratorExt : ItemGenerator
{
public ItemGeneratorExt(SfListView listview) : base(listview)
{
}
protected override ListViewItem OnCreateListViewItem(int rowIndex, ItemType type, object data = null)
{
if(type == ItemType.Record)
{
return new ListViewItemExt();
}
return base.OnCreateListViewItem(rowIndex, type, data);
}
} |
this.listView.ItemGenerator = new ItemGeneratorExt(this.listView);
|
public class ListViewItemExt : ListViewItem
{
private object itemData;
public object ItemData
{
get { return itemData; }
set
{
itemData = value;
OnPropertyChanged("ItemData");
}
}
protected override void OnBindingContextChanged()
{
this.ItemData = this.BindingContext;
base.OnBindingContextChanged();
}
} |
[assembly:ExportRenderer(typeof(ListViewItemExt),typeof(ItemRendererExt))]
namespace ListView_CustomRenderer.Droid
{
public class ItemRendererExt : ItemRenderer
{
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if(e.PropertyName == "ItemData")
{
var textView = new TextView(this.Context);
textView.Text = "Runtime View";
this.SetNativeControl(textView);
}
}
}
} |
Hey Ganesan,
thank you for your work and effort! That's what I was looking for :-) The ads are now loaded only once or twice (depending on the list elements on screen) and are then recycled. Great! If you like to see an example to check if my implementation was the from you intended way, then you can have a look here: https://goo.gl/SRW6yS.
Kind regards,
Daniel
Hello Dinesh,
sadly I have to reopen this issue. Your solution seems not to work with DataTemplateSelectors. Please have a look at this example: SyncFusion_ItemRecycle_TemplateSelector
As you can see, when you scroll down and up through the list, the colored text cells (Hi from Android xyz) are always recreated. The background colors and the xyz numbers changes everytime.
Can you please adapt your solution so that it works with DataTemplateSelectors too?
Kind regards
Daniel