Some different requirement i'm using nested ListView in XAMRIN form. It's working perfect in IOS. But in Android it's crashing when scrolling the ListView item then giving the following exception as:
Unable to activate instance of type Xamarin.Forms.Platform.Android.ListViewAdapter from native handle 0x7fd2839b14 (key_handle 0x4219316).
No constructor found for Xamarin.Forms.Platform.Android.ListViewAdapter::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership
Exception of type 'Java.Interop.JavaLocationException' was thrown.
XAML Code:
<StackLayout>
<ListView
HasUnevenRows="True"
SeparatorVisibility="None"
ItemsSource="{Binding PAContactDetailList,Mode=TwoWay}" HeightRequest="{Binding HeightList}" x:Name="lstRoot">
<!-- <ListView.Behaviors>
<commonClass:AutoSizeBehavior/>
</ListView.Behaviors>-->
<ListView.ItemTemplate>
<DataTemplate>
<customControls:CustomViewCellList>
<StackLayout>
<Grid VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Padding="10,0,10,0" >
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="1"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30"/>
<ColumnDefinition Width="5"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackLayout Orientation="Vertical" Spacing="5" Grid.Column="2">
<Label Text="PA Name" FontSize="17" TextColor="#A0A4A3"/>
<Label Text="{Binding FullName}" FontSize="17" TextColor="Black"/>
<BoxView BackgroundColor="#979797" HeightRequest=".5" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"/>
</StackLayout>
<Image Source="Phone" Aspect="AspectFit" Grid.Row="1" VerticalOptions="Start" HeightRequest="25"/>
<StackLayout Orientation="Vertical" Grid.Row="1" Spacing="5" Grid.Column="2" >
<StackLayout>
<StackLayout.GestureRecognizers>
<TapGestureRecognizer
Tapped="Handle_Tapped" CommandParameter="{Binding PAMobileNumber}"/>
</StackLayout.GestureRecognizers>
<Label Text="Mobile" FontSize="17" TextColor="#A0A4A3"/>
<Label Text="{Binding PAMobileNumber}" FontSize="17" TextColor="Black"/>
</StackLayout>
<BoxView BackgroundColor="#979797" HeightRequest=".5" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"/>
</StackLayout>
<Image Source="Whatsapp" Aspect="AspectFit" VerticalOptions="StartAndExpand" Grid.Row="2" HeightRequest="25"/>
<StackLayout Orientation="Vertical" Spacing="5" Grid.Column="2" Grid.Row="2">
<Label Text="WhatsApp" FontSize="17" TextColor="#A0A4A3"/>
<Label Text="{Binding PAWhatsappNumber}" FontSize="17" TextColor="Black"/>
<BoxView BackgroundColor="#979797" HeightRequest=".5" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"/>
</StackLayout>
<customControls:HideScrollListView Grid.ColumnSpan="3" Grid.Row="4"
HasUnevenRows="True"
SeparatorVisibility="None"
ItemsSource="{Binding PAContactDetails}" ItemSelected="Handle_ItemSelected" HeightRequest="{Binding HeightContact}">
<!--<ListView.Behaviors>
<commonClass:AutoSizeBehavior/>
</ListView.Behaviors>-->
<customControls:HideScrollListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid x:Name="rootGrid" >
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="col1" Width="30"/>
<ColumnDefinition x:Name="col2" Width="5"/>
<ColumnDefinition x:Name="col3" Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="10"/>
</Grid.RowDefinitions>
<Image Source="{Binding PhoneImage}" Aspect="AspectFit" VerticalOptions="Start" HeightRequest="25"/>
<StackLayout Grid.Column="2" Spacing="7" Orientation="Vertical" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" >
<Label Text="{Binding ContactType}" FontSize="17" TextColor="#A0A4A3"/>
<Label Text="{Binding Phone}" FontSize="17" TextColor="Black"/>
<BoxView BackgroundColor="#979797" HeightRequest=".5" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"/>
</StackLayout>
</Grid>
</ViewCell>
</DataTemplate>
</customControls:HideScrollListView.ItemTemplate>
</customControls:HideScrollListView>
<Image Source="Email" Aspect="AspectFit" VerticalOptions="StartAndExpand" Grid.Row="6" HeightRequest="25"/>
<StackLayout Orientation="Vertical" Spacing="5" Grid.Column="2" Grid.Row="6">
<StackLayout>
<StackLayout.GestureRecognizers>
<TapGestureRecognizer
Tapped="Handle_Tapped" CommandParameter="{Binding PAPrimaryEmail}"/>
</StackLayout.GestureRecognizers>
<Label Text="Email" FontSize="17" TextColor="#A0A4A3"/>
<Label Text="{Binding PAPrimaryEmail,Mode=TwoWay}" FontSize="17" TextColor="Black"/>
</StackLayout>
<BoxView BackgroundColor="#979797" HeightRequest=".5" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"/>
</StackLayout>
<Image Source="Phone" Aspect="AspectFit" Grid.Row="3" VerticalOptions="Start" HeightRequest="25"/>
<StackLayout Orientation="Vertical" Spacing="5" Grid.Column="2" Grid.Row="3" >
<StackLayout>
<StackLayout.GestureRecognizers>
<TapGestureRecognizer
Tapped="Handle_Tapped" CommandParameter="{Binding PAWorkNumber}"/>
</StackLayout.GestureRecognizers>
<Label Text="Work" FontSize="17" TextColor="#A0A4A3"/>
<Label Text="{Binding PAWorkNumber}" FontSize="17" TextColor="Black"/>
</StackLayout>
<BoxView BackgroundColor="#979797" HeightRequest=".5" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"/>
</StackLayout>
<StackLayout Orientation="Vertical" Spacing="5" Grid.ColumnSpan="3" Grid.Row="8">
<customControls:HideScrollListView
HasUnevenRows="True"
SeparatorVisibility="None"
ItemsSource="{Binding ContactEmailList}" ItemSelected="Handle_ItemSelected" HeightRequest="{Binding HeightEmail}">
<customControls:HideScrollListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid x:Name="rootGrid" >
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="col1" Width="30"/>
<ColumnDefinition x:Name="col2" Width="5"/>
<ColumnDefinition x:Name="col3" Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Image Source="Email" Aspect="AspectFit" VerticalOptions="Start" HeightRequest="25"/>
<StackLayout Grid.Column="2" Spacing="7" Orientation="Vertical" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" >
<Label Text="{Binding EmailType}" FontSize="17" TextColor="#A0A4A3"/>
<Label Text="{Binding Email}" FontSize="17" TextColor="Black"/>
<BoxView BackgroundColor="#979797" HeightRequest=".5" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"/>
</StackLayout>
</Grid>
</ViewCell>
</DataTemplate>
</customControls:HideScrollListView.ItemTemplate>
</customControls:HideScrollListView>
</StackLayout>
<BoxView HeightRequest="1" BackgroundColor="Black" IsVisible="false" Grid.Row="9" Grid.ColumnSpan="3" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"/>
</Grid>
</StackLayout>
</customControls:CustomViewCellList>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
ListView Custom Renderer Code:
public class HideScrollListViewRender:ListViewRenderer
{
Context _context;
public HideScrollListViewRender(Context context):base(context)
{
_context = context;
}
protected override void OnDetachedFromWindow()
{
if (Element == null)
return;
base.OnDetachedFromWindow();
}
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.ListView> e)
{
base.OnElementChanged(e);
}
CellView Custom Renderer Code:
public class CustomAllViewCellRenderer:ViewCellRenderer
{
public override UIKit.UITableViewCell GetCell(Cell item, UIKit.UITableViewCell reusableCell, UIKit.UITableView tv)
{
var cell = base.GetCell(item, reusableCell, tv);
if (cell != null)
cell.SelectionStyle = UIKit.UITableViewCellSelectionStyle.None;
return cell;
}
}
The exceptions is only in xamarin form Android. What's wrong with the code?