4

I am trying to implement a grouped listview on Android similar to iOS. Therefore, I am trying to write my own custom MvxAdapter that supports grouped section headers. The default MvxListView constructed from axml will create a default MvxAdapter. Since I need to supply my own custom MvxAdapter, I need to create the MvxListview programmatically so I can pass in my own adapter. The problem I am having is at the time of OnCreate of my android view where I try to construct my custom MvxAdapter, the Android binding context is null as retrieved from

MvxAndroidBindingContextHelpers.Current()

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

Stuart
  • 66,722
  • 7
  • 114
  • 165
user2395286
  • 457
  • 7
  • 18

1 Answers1

5

There's no examples of creating an MvxListView programatically - almost all Android UI controls are created in axml in the current samples.

For creating custom adapters, there are a few examples around, inclduing:


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

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


In the event that you ever do want to push a 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

Stuart
  • 66,722
  • 7
  • 114
  • 165