我目前正在为Android和iOS实施跨平台应用程序。
由于我想使用MvvmCross和弹出导航,如果发现Benjamin Hysell的演示(使用DrawerLayout)非常有帮助:
代码: https://github.com/benhysell/V.FlyoutTest
根据此代码,我想在弹出导航中的菜单下添加一些额外的控件。
所以在HomeView中,我在方法
的末尾添加了以下代码protected override void OnCreate(Bundle savedInstanceState)
{
// ....
var layout = this.BindingInflate(Resource.Layout.DrawerFooterView, null);
drawerList.AddFooterView(layout);
}
现在,当我启动应用程序时,我可以看到everthing就好了,包括我在弹出菜单中的额外控件。但是,一旦我点击一个菜单项,我在MvvmCross中得到一个NullReferenceException:
04-25 17:42:20.892 I/MonoDroid(32443): UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
04-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:261
04-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>
任何人都可以为这个问题提供帮助,因为我没有想法。
任何帮助都将不胜感激。
答案 0 :(得分:4)
我不明白为什么向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;
}
};
答案 1 :(得分:0)
目前,MvxListView 不支持 AddHeader / AddFooter方法。
在极端情况下,您可以为导航列表视图添加自定义项: Polymorphic Lists
因此,您将拥有两种类型的项目:
1 - 默认导航行
2 - 页脚,在您的情况下