2014-04-25 4 views
3

현재 Android 및 iOS 용 crossplatform-app를 구현 중입니다.NavigationDrawer MvxListView의 AddFooter 메소드 - NullReferenceException

매우 도움 (A DrawerLayout를 사용하여) 벤자민 Hysell의 데모를 발견하면 나는 MvvmCross과 플라이 아웃 내비게이션을 사용할 이후 :

코드 : https://github.com/benhysell/V.FlyoutTest

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

기반 이 코드에서는 플라이 아웃 탐색 메뉴 아래에 몇 가지 추가 컨트롤을 추가하려고했습니다.

그래서 HomeView에, 나는 응용 프로그램을 시작할 때, 내가 플라이 아웃 메뉴에 내 여분의 컨트롤을 포함, 모든게가 잘 볼 수있는, 지금
protected override void OnCreate(Bundle savedInstanceState) 
{ 
    // .... 

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

방법

의 끝에 다음 코드를 추가했다. 그러나 곧 나는 내가 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

어떤 레이아웃과 뷰 모델처럼 보이나요? – Kiliman

+0

@Kiliman, 'DrawerFooterView'의 레이아웃은 TextViews가있는 간단한 LinearLayout이며 'DrawerFooterViewModel'은 아직 비어 있습니다. 이러한 TextViews는 아직 어떤 속성에도 바인딩되어 있지 않기 때문입니다. – gridr

+0

아마도 https://github.com/MvvmCross/MvvmCross/issues/602에 링크되어 있습니다. – Stuart

답변

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

예, 작동하지만 애니메이션 표시/숨기기는 목록보기 스크롤과 다릅니다. –

+0

답장을 위해 @Cheesebaron에게 감사드립니다.결국에는 가시성 부분이 없어도 이와 비슷한 것을 구현했습니다. 방금 ​​목록의 바닥 글을 사용하는 것이 유용하고 편리한 솔루션이라고 생각했습니다. – gridr

+0

장기적으로 MvxAdapter의 문제는 어떻게 든 고쳐 져야한다고 생각합니다. 문제가되는 제안 된 솔루션이 이미 있다고 생각합니다. [# 602] (https://github.com/MvvmCross/MvvmCross/issues/602) – Cheesebaron

0

당분간 MvxListView 은 지원되지 않습니다. AddHeader/AddFooter 메소드. 극단적 인 경우에

, 당신은 당신의 탐색 목록보기에 대한 사용자 정의 항목을 추가 할 수 있습니다 Polymorphic Lists

은 따라서 당신이 항목의 두 가지 유형이됩니다

1 - 기본 탐색 행

2 - 바닥 글을, 귀하의 사례에서