Pregunta

I am currently implementing a crossplatform-app for Android and iOS.

Since I want to use MvvmCross and a flyout-navigation, if found Benjamin Hysell's demo (using a DrawerLayout) extremely helpful:

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

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

Based on this code, I wanted to add some additional controls underneath the menu inside the flyout navigation.

So in HomeView, I added the following code at the end of method

protected override void OnCreate(Bundle savedInstanceState)
{
    // ....

    var layout = this.BindingInflate(Resource.Layout.DrawerFooterView, null);
    drawerList.AddFooterView(layout);
}

Now, when I start the app, i can see everthing just fine, including my extra controls in the flyout menu. But as soon i tap a menu item, I get a NullReferenceException in MvvmCross:

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>

Can anyone provide assistance to this issue, because I am out of ideas.

Any help would be appreciated.

¿Fue útil?

Solución

I don't understand why adding a Header or Footer view to a ListView is such a big deal.

Sure there are some quirks with adding them directly to MvxListView, but you could do the work yourself with very little effort.

<?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>

Then you can add a EventHandler to the Scroll event if you want to show/hide the footer whether you have reached the bottom:

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;
    }
};

Otros consejos

For the time being, MvxListView not supported AddHeader/AddFooter methods.

In extreme cases, you can add custom item for your navigation listview: Polymorphic Lists

Thus you will have two type of items:

1 - default navigation row

2 - footer, in your case

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top