android-MvxListView中的NavigationDrawer AddFooter方法-NullReferenceException

android-MvxListView中的NavigationDrawer AddFooter方法-NullReferenceException,第1张

概述我目前正在为Android和iOS实现一个crossplatform-app.由于我想使用MvvmCross和d出菜单,因此如果发现本杰明·海塞尔(BenjaminHysell)的演示(使用DrawerLayout)非常有用:码:https://github.com/benhysell/V.FlyoutTest描述:http://benjaminhysell.com/archive/2014/04/mvvmcross-

我目前正在为Android和iOS实现一个crossplatform-app.

由于我想使用MvvmCross和d出菜单,因此如果发现本杰明·海塞尔(Benjamin Hysell)的演示(使用DrawerLayout)非常有用:

码:
https://github.com/benhysell/V.FlyoutTest

描述:
http://benjaminhysell.com/archive/2014/04/mvvmcross-flyoutnavigation-hamburger-menu-sliding-menu-for-android-and-ios/

基于此代码,我想在d出菜单内的菜单下方添加一些其他控件.

因此,在HomeVIEw中,我在方法末尾添加了以下代码

protected overrIDe voID OnCreate(Bundle savedInstanceState){    // ....    var layout = this.BindingInflate(Resource.Layout.DrawerFooterVIEw, null);    drawerList.AddFooterVIEw(layout);}

现在,当我启动该应用程序时,我可以看到一切正常,包括d出菜单中的其他控件.但是,一旦我点击一个菜单项,我就会在MvvmCross中得到一个NullReferenceException:

04-25 17:42:20.892 I/MonoDroID(32443): UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object04-25 17:42:20.892 I/MonoDroID(32443): at CirrIoUs.MvvmCross.Binding.DroID.VIEws.MvxListVIEw.ExecuteCommandOnItem (System.windows.input.ICommand,int) <IL 0x0000b, 0x000a0>04-25 17:42:20.892 I/MonoDroID(32443): at CirrIoUs.MvvmCross.Binding.DroID.VIEws.MvxListVIEw.<EnsureItemClickOverloaded>b__0 (object,AndroID.Widget.AdapterVIEw/ItemClickEventArgs) <IL 0x0000d, 0x000a7>04-25 17:42:20.892 I/MonoDroID(32443): at AndroID.Widget.AdapterVIEw/IOnItemClickListenerImplementor.OnItemClick (AndroID.Widget.AdapterVIEw,AndroID.VIEws.VIEw,int,long) [0x0000d] in /Users/builder/data/lanes/monodroID-mlion-monodroID-4.12-serIEs/a1e3982a/source/monodroID/src/Mono.AndroID/platforms/androID-15/src/generated/AndroID.Widget.AdapterVIEw.cs:26104-25 17:42:20.892 I/MonoDroID(32443): at (wrapper dynamic-method) object.289e379c-ed35-42d0-8505-cc91a6c90d7b (intptr,intptr,intptr,intptr,int,long) <IL 0x00029, 0x0009b>

任何人都可以为这个问题提供帮助,因为我没有主意.

任何帮助,将不胜感激.

解决方法:

我不明白为什么将header或Footer视图添加到ListVIEw这么大的原因.

当然,有些将它们直接添加到MvxListVIEw的怪癖,但是您可以自己做一点工作.

<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    xmlns:local="http://schemas.androID.com/apk/res-auto"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent">    <linearLayout        androID:ID="@+ID/header"        androID:orIEntation="vertical"        androID:layout_alignParenttop="true"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content">        <!-- header content here -->    </linearLayout>    <linearLayout        androID:ID="@+ID/footer"        androID:orIEntation="vertical"        androID:layout_alignParentBottom="true"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content">        <!-- Footer content here -->    </linearLayout>    <MvxListVIEw        androID:ID="@+ID/ListvIEw"        androID:layout_wIDth="match_parent"        androID:layout_height="match_parent"        androID:layout_below="@+ID/header"        androID:layout_above="@+ID/footer"        local:MvxBind="ItemsSource Items; ItemSelected SelectedItem"/></relativeLayout>

然后,如果要显示/隐藏页脚是否到达底部,可以将EventHandler添加到Scroll事件中:

var footer = FindVIEwByID<linearLayout>(Resource.ID.footer);var lv = FindVIEwByID<MvxListVIEw>(Resource.ID.ListvIEw);lv.Scroll += (s, e) =>{    var lastItem = e.FirstVisibleItem + e.VisibleItemCount;    if(lastItem == e.TotalitemCount)    {        // we are at the end of the List        // maybe do some animation before showing it        footer.Visibility = VIEwStates.Visible;    }    else    {        footer.Visibility = VIEwStates.Gone;    }};
总结

以上是内存溢出为你收集整理的android-MvxListView中的NavigationDrawer AddFooter方法-NullReferenceException全部内容,希望文章能够帮你解决android-MvxListView中的NavigationDrawer AddFooter方法-NullReferenceException所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1088651.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存