MvxRecyclerView, MvxListView, and MvxSpinner can all be used to show a collection to the user. All three support using an item template to allow custom cells in the list to take advantage of MvvmCross data binding. If you do not specify an item template for an MvxListView or MvxSpinner then each cell of the list will be displayed using ToString(). If you do not specify an item template for an MvxRecyclerView then an exception is thrown at runtime. MvxRecyclerView seems to be programmed to require a MvxItemTemplate without providing a default like MvxListView and MvxSpinner. Does it make sense to update MvxRecyclerView to work the same way as MvxSpinner and MvxListView?
Create a MvxRecyclerView in AXML file.
Do not specify the MvxItemTemplate for the MvxRecyclerView.
<MvvmCross.Droid.Support.V7.RecyclerView.MvxRecyclerView
android:id="@+id/code_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:MvxBind="ItemsSource Codes; ItemClick SelectCodeCommand;" />
<MvxRecyclerView> XML tag with <MvxSpinner> or <MvxListView> then the list renders (using .ToString) and no exceptions are thrown.I think MvxRecyclerView should work like MvxListView and MvxSpinner and populate the list using ToString() by default if no item template is used.
Exception is thrown at runtime: Android.Content.Res.Resources+NotFoundException: Resource ID #0x0. This happens because the item template identifier is an int initialized to 0 then not set by my code.
UNHANDLED EXCEPTION:
Android.Content.Res.Resources+NotFoundException: Resource ID #0x0
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <657aa8fea4454dc898a9e5f379c58734>:0
at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualObjectMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00089] in <e736913786c2475188869561ae512b72>:0
at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualObjectMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0005d] in <e736913786c2475188869561ae512b72>:0
at Android.Views.LayoutInflater.Inflate (System.Int32 resource, Android.Views.ViewGroup root, System.Boolean attachToRoot) [0x0005a] in <8211f1f12f9e45838d631abf63e51c79>:0
at MvvmCross.Binding.Droid.Views.MvxLayoutInflater.Inflate (System.Int32 resource, Android.Views.ViewGroup root, System.Boolean attachToRoot) [0x0003e] in C:\projects\mvvmcross\MvvmCross\Binding\Droid\Views\MvxLayoutInflater.cs:137
at MvvmCross.Binding.Droid.BindingContext.MvxAndroidBindingContext.CommonInflate (System.Int32 resourceId, Android.Views.ViewGroup viewGroup, System.Boolean attachToRoot) [0x00013] in C:\projects\mvvmcross\MvvmCross\Binding\Droid\BindingContext\MvxAndroidBindingContext.cs:52
at MvvmCross.Binding.Droid.BindingContext.MvxAndroidBindingContext.BindingInflate (System.Int32 resourceId, Android.Views.ViewGroup viewGroup, System.Boolean attachToRoot) [0x00000] in C:\projects\mvvmcross\MvvmCross\Binding\Droid\BindingContext\MvxAndroidBindingContext.cs:36
at MvvmCross.Droid.Support.V7.RecyclerView.MvxRecyclerAdapter.InflateViewForHolder (Android.Views.ViewGroup parent, System.Int32 viewType, MvvmCross.Binding.Droid.BindingContext.IMvxAndroidBindingContext bindingContext) [0x0000d] in C:\projects\mvvmcross\MvvmCross-AndroidSupport\MvvmCross.Droid.Support.V7.RecyclerView\MvxRecyclerAdapter.cs:175
at MvvmCross.Droid.Support.V7.RecyclerView.MvxRecyclerAdapter.OnCreateViewHolder (Android.Views.ViewGroup parent, System.Int32 viewType) [0x00018] in C:\projects\mvvmcross\MvvmCross-AndroidSupport\MvvmCross.Droid.Support.V7.RecyclerView\MvxRecyclerAdapter.cs:157
at Android.Support.V7.Widget.RecyclerView+Adapter.n_OnCreateViewHolder_Landroid_view_ViewGroup_I (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_parent, System.Int32 viewType) [0x0000f] in <1c3b474ba0bc45cba6ec33f4b4b4b99a>:0
at (wrapper dynamic-method) System.Object:1e886010-d244-4f54-a83a-39d099b08368 (intptr,intptr,intptr,int)
--- End of managed Android.Content.Res.Resources+NotFoundException stack trace ---
Version: 5.6.3
Platform:
Thank you for reporting this issue. You are totally right, there is a inconsistency with how MvxRecyclerView works when not supplying a template or selector, compared to MvxListView. We should probably just copy what MvxListView does in its ViewHolder along with the template it uses. This will make it even easier to switch between implementation.
We will try to resolve this issue and provide PR tomorrow on Xamarin Meetup in Gdansk [PL]
You are very welcome to do so!
Seems to be occurring in MvvmCross 6.3
Please create a new issue describing _your_ scenario, instead of leaving a generic comment that something implied is happening to you. We are happy to help.
Most helpful comment
We will try to resolve this issue and provide PR tomorrow on Xamarin Meetup in Gdansk [PL]