ViewPager2's FragmentStateAdapter binding mismatches inherited generic `OnBindViewHolder` method
See original GitHub issueXamarin.Android Version (eg: 6.0):
Xamarin.Android 10.1.4.0 (d16-4 e44d1ae)
Operating System & Version (eg: Mac OSX 10.11):
Windows 10 1909 (IDE: Visual Studio 2019 16.4.5)
Support Libraries Version (eg: 23.3.0):
Xamarin.AndroidX.ViewPager2 1.0.0
Describe your Issue:
The class FragmentStateAdapter which is used for the new ViewPager2 seems to have a Java binding issue regarding inheritance.
In Java, the FragmentStateAdapter class inherits the RecyclerView.Adapter class, which has the abstract onBindViewHolder
method. This abstract method is implemented and sealed (marked final) by the FragmentStateAdapter class to get a chunk of its functionality working. In Java and Kotlin this means any implementation of FragmentStateAdapter does not require implementation of the onBindViewHolder
method.
In the Xamarin binding there seems to be a mismatch in inheritance however. The signature of the of the OnBindViewHolder
implementation in FragmentStateAdapter seems to mismatch with the OnBindViewHolder
in the parent RecyclerView.Adapter class.
On the C# side of things, this causes the responsibility of implementing the abstract OnBindViewHolder
in RecyclerView.Adapter to cascade down to the classes that inherit FragmentStateAdapter (since the implementation in FragmentStateAdapter mismatches it is now missing as far as the C# compiler is concerned)
If I try to implement the method in my FragmentStateAdapter subclasses to make sure the C# compiler shows no errors, the Java build error shown below appears instead:
JAVAC0000: error: name clash: onBindViewHolder(ViewHolder,int) in MyTestActivity_MyPagerAdapter and onBindViewHolder(VH,int) in Adapter have the same erasure, yet neither overrides the other
public void onBindViewHolder (androidx.recyclerview.widget.RecyclerView.ViewHolder p0, int p1) where VH is a type-variable: VH extends ViewHolder declared in class Adapter
Possible cause
The issue seems to be caused by the following mismatch:
In Java, the generic signature onBindViewHolder(VH holder, int position)
(where VH is a generic defined in the RecyclerView.Adapter class signature) is properly inherited by the method signature onBindViewHolder(FragmentViewHolder holder, int position)
.
In C#/Xamarin however, it seems the RecyclerView.Adapter doesn’t have this generic aspect bound. Instead using the ViewHolder base type in place of the generic.
This likely causes the OnBindViewHolder(FragmentViewHolder holder, int position)
method in the FragmentStateAdapter to mismatch with the now non-generic OnBindViewHolder(ViewHolder holder, int position)
method in the RecyclerView.Adapter class
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:7 (2 by maintainers)
@leonluc-dev @vitalykovalgit @ryanthompson0123 Fix released/published 1.0.0.1
https://www.nuget.org/packages/Xamarin.AndroidX.ViewPager2/1.0.0.1
https://github.com/xamarin/AndroidX/tree/20200327-stable-release-fix-issue0066-ViewPager2.FragmentStateAdapter.OnBindViewHolder
@leonluc-dev If the issue is fixed/solved I would appreciate if you would close the issue yourself. Thanks.
Still present in ver. 1.0.0.16