MvvmCross:如何以编程方式构建具有自定义适配器的MvxListView? [英] MvvmCross: How to programmatically construct an MvxListView with custom adapter?

查看:437
本文介绍了MvvmCross:如何以编程方式构建具有自定义适配器的MvxListView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现在Android分组列表视图相似到iOS。因此,我想编写支持分组节标题我自己的自定义MvxAdapter。从AXML构建默认MvxListView将创建一个默认MvxAdapter。因为我需要提供自己的定制MvxAdapter,我需要以编程方式创建MvxListview所以我可以在我自己的适配器通过。我遇到的问题是在的OnCreate 我在那里我试图建立我的自定义MvxAdapter Android设备上查看的时间,Android的结合上下文为null从

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()

有一个自定义MvxAdapter与v3的API编程构建一个MvxListView的例子吗?

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

推荐答案

有没有编程创建MvxListView的例子 - 在AXML创建当前样本中,几乎所有的Andr​​oid UI控件

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

有关创建自定义适配器,也有几个例子身边,inclduing:

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


  • 在集合中的多态列表的例子:的https://github.com/slodge/MvvmCross-Tutorials/tree/master/Working%20With%20Collections

  • 在一个先进的例子<一个href=\"https://github.com/slodge/MvvmCross-Tutorials/blob/master/Sample%20-%20CirriousConference/Cirrious.Conference.UI.Droid/Views/SessionsLists/BaseSessionListView.cs\" rel=\"nofollow\">https://github.com/slodge/MvvmCross-Tutorials/blob/master/Sample%20-%20CirriousConference/Cirrious.Conference.UI.Droid/Views/SessionsLists/BaseSessionListView.cs

另外,你可以,当然,继承 CustomListView MvxListView 然后可以通过在你的自定义适配器作为构造函数的一部分。

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

更多关于创建和使用自定义视图,看到的http://slodge.blogspot.co.uk/2013/05/n18-android-custom-controls-n1-days-of.html

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
  }

这是XAML通货膨胀期间究竟发生了什么 - 看:<一href=\"https://github.com/slodge/MvvmCross/blob/v3/Cirrious/Cirrious.MvvmCross.Binding.Droid/BindingContext/MvxAndroidBindingContext.cs#L47\" rel=\"nofollow\">https://github.com/slodge/MvvmCross/blob/v3/Cirrious/Cirrious.MvvmCross.Binding.Droid/BindingContext/MvxAndroidBindingContext.cs#L47

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

这篇关于MvvmCross:如何以编程方式构建具有自定义适配器的MvxListView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆