MvvmCross: How to programmatically build an MvxListView with a custom adapter?

I am trying to implement a grouped list on Android similar to iOS. So I am trying to write my own MvxAdapter, which supports grouped section headers. By default, an MvxListView created from axml will create a default MvxAdapter. Since I need to provide my own MvxAdapter, I need to create an MvxListview programmatically so that I can switch to my own adapter. The problem I am facing is the OnCreate time of my android view, where I am trying to create my custom MvxAdapter, the Android binding context is null derived from

 MvxAndroidBindingContextHelpers.Current() 

Is there an example of creating an MvxListView programmatically using a custom MvxAdapter with v3 API?

+4
source share
1 answer

There are no examples of creating MvxListView programmatically - almost all Android UI controls are created in axml in the current selections.

There are several examples for creating custom adapters, including:


Alternatively, you can, of course, inherit CustomListView from MvxListView and then pass your custom adapter as part of the constructor.

For more information about creating and using custom views, see http://slodge.blogspot.co.uk/2013/05/n18-android-custom-controls-n1-days-of.html


If you ever want to push the context onto the stack, you can do this using:

  using (new MvxBindingContextStackRegistration<IMvxAndroidBindingContext>(**TheContext**)) { // create your controls here } 

This is exactly what happens during xaml inflation - see: https://github.com/slodge/MvvmCross/blob/v3/Cirrious/Cirrious.MvvmCross.Binding.Droid/BindingContext/MvxAndroidBindingContext.cs#L47

+5
source

Source: https://habr.com/ru/post/1482825/