2016-06-17 5 views
0

フラグメントを持つビューページャーを持っているので、左右にスワイプしてフラグメントを切り替えることができます。断片の一つから、私はポップアップを表示したい。私はこれがListPopupWindowである必要があると仮定します。私が持っているものは、EditTextフィールドで、いくつかのデータを入力することができます。私はそれからエントリーをチェックし、一致するものが1つあればそれはいいです。しかし、複数の一致がある場合は、どちらが正しい結果かを選択できるようにポップアップウィンドウを表示する必要があります。これがListPopupWindowであると仮定した理由です。リストをポップアップの直前に動的に埋め込む必要があります。ポップアップではなく、リストビューで新しいフラグメントをスライドさせるだけでいいのかどうか、私は熟考しました。しかし、私はListPopupWindowを使用してこの時点でこれを実行しようとしていますが、Java.Lang.NullPointerExceptionエラーが発生しています。ここで私が今までに持っているコードを示します。このコードは、いつでも呼び出せるメソッドにあります。ListPopupWindowが私のフラグメントからJava.Lang.NullPointerExceptionエラーを返す

  ListPopupWindow popup = new ListPopupWindow(context); //context is passed in during onCreate of this fragment 

     List<string> listForPopup = new List<string>(); //Create a new list to show on the popup for the user to select 

     foreach (var c in validationResults) //Iterate through each of the possible results that the user must select 
     { 
      string name = lookupCourier(c.Item1); //The results only have an ID number, call lookup method to get the name from the ID. 
      listForPopup.Add(name); //Add to the new list. 
     } 

     var adapter = new ArrayAdapter<string>(context, Android.Resource.Layout.SimpleListItem1, listForPopup); //Array adapter from the list. 

     popup.SetAdapter(adapter); //Set the adapter to the popup list. 
     popup.Width = 300; //Set the width of the popup. 
     popup.Height = WindowManagerLayoutParams.WrapContent; //Have the popup window wrap the content. May have one or many to select from. Are there scroll bars? 
     popup.Modal = true; 
     popup.ItemClick += Popup_ItemClick; //Event handler to fire when the user selects the one item in the list. 


     popup.Show(); //Show popup. NOTE: This is there I get the null excpetion. 

そして、ここに例外からスタックトレースは、(私は倍数があると思います)です:

06-17 22:50:59.674 E/mono (4198): 
06-17 22:50:59.674 E/mono (4198): Unhandled Exception: 
06-17 22:50:59.674 E/mono (4198): Java.Lang.NullPointerException: Exception of type 'Java.Lang.NullPointerException' was thrown. 
06-17 22:50:59.674 E/mono (4198): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x0000c] in /Users/builder/data/lanes/2923/52635947/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 
06-17 22:50:59.674 E/mono (4198): at Java.Interop.JniEnvironment+InstanceMethods.CallVoidMethod (JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00084] in /Users/builder/data/lanes/2923/52635947/source/Java.Interop/src/Java.Interop/Java.Interop/JniEnvironment.g.cs:11643 
06-17 22:50:59.674 E/mono (4198): at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00031] in /Users/builder/data/lanes/2923/52635947/source/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:26 
06-17 22:50:59.674 E/mono (4198): at Android.Widget.ListPopupWindow.Show() [0x00000] in /Users/builder/data/lanes/2923/52635947/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Widget.ListPopupWindow.cs:1527 
06-17 22:50:59.674 E/mono (4198): at PocketPacTracAndroid.Track.popupToSelectCourier (System.Collections.Generic.List`1 validationResults) [0x000a4] in C:\Projects\PocketPacTracAndroid\PocketPacTracAndroid\PocketPacTracAndroid\Track.cs:225 
06-17 22:50:59.674 E/mono (4198): at PocketPacTracAndroid.Track.validateBarcode (System.String rawBarcode) [0x0014e] in C:\Projects\PocketPacTracAndroid\PocketPacTracAndroid\PocketPacTracAndroid\Track.cs:192 
06-17 22:50:59.674 E/mono (4198): at PocketPacTracAndroid.Track.Barcode_KeyPress (System.Object sender, Android.Views.KeyEventArgs e) [0x0001c] in C:\Projects\PocketPacTracAndroid\PocketPacTracAndroid\PocketPacTracAndroid\Track.cs:88 
06-17 22:50:59.674 E/mono (4198): at Android.Views.View+IOnKeyListenerImplementor.OnKey (Android.Views.View v, Keycode keyCode, Android.Views.KeyEvent e) [0x00018] in /Users/builder/data/lanes/2923/52635947/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Views.View.cs:2854 
06-17 22:50:59.674 E/mono (4198): at Android.Views.View+IOnKeyListenerInvoker.n_OnKey_Landroid_view_View_ILandroid_view_KeyEvent_ (IntPtr jnienv, IntPtr native__this, IntPtr native_v, Int32 native_keyCode, IntPtr native_e) [0x0001c] in /Users/builder/data/lanes/2923/52635947/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Views.View.cs:2787 
06-17 22:50:59.674 E/mono (4198): at (wrapper dynamic-method) System.Object:22b2513e-fc1d-45f2-938f-fbc85af3219a (intptr,intptr,intptr,int,intptr) 
06-17 22:50:59.674 E/mono (4198): --- End of managed exception stack trace --- 
06-17 22:50:59.674 E/mono (4198): java.lang.NullPointerException 
06-17 22:50:59.674 E/mono (4198): at android.widget.PopupWindow.getMaxAvailableHeight(PopupWindow.java:1219) 
06-17 22:50:59.674 E/mono (4198): at android.widget.ListPopupWindow.buildDropDown(ListPopupWindow.java:1090) 
06-17 22:50:59.674 E/mono (4198): at android.widget.ListPopupWindow.show(ListPopupWindow.java:524) 
06-17 22:50:59.674 E/mono (4198): at mono.android.view.View_OnKeyListenerImplementor.n_onKey(Native Method) 
06-17 22:50:59.674 E/mono (4198): at mono.android.view.View_OnKeyListenerImplementor.onKey(View_OnKeyListenerImplementor.java:30) 
06-17 22:50:59.674 E/mono (4198): at android.view.View.dispatchKeyEvent(View.java:7081) 
06-17 22:50:59.674 E/mono (4198): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1358) 
06-17 22:50:59.674 E/mono (4198): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1358) 
06-17 22:50:59.674 E/mono (4198): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1358) 
06-17 22:50:59.674 E/mono (4198): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1358) 
06-17 22:50:59.674 E/mono (4198): at android.support.v4.view.ViewPager.dispatchKeyEvent(ViewPager.java:2567) 
06-17 22:50:59.674 E/mono (4198): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1358) 
06-17 22:50:59.674 E/mono (4198): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1358) 
06-17 22:50:59.674 E/mono (4198): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1358) 
06-17 22:50:59.674 E/mono (4198): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1358) 
06-17 22:50:59.674 E/mono (4198): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1892) 
06-17 22:50:59.674 E/mono (4198): at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1369) 
06-17 22:50:59.674 E/mono (4198): at android.app.Activity.dispatchKeyEvent(Activity.java:2356) 
06-17 22:50:59.674 E/mono (4198): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1819) 
06-17 22:50:59.674 E/mono (4198): at android.view.ViewRootImpl.deliverKeyEventPostIme(ViewRootImpl.java:3575) 
06-17 22:50:59.674 E/mono (4198): at android.view.ViewRoot 
06-17 22:50:59.674 E/mono-rt (4198): [ERROR] FATAL UNHANDLED EXCEPTION: Java.Lang.NullPointerException: Exception of type 'Java.Lang.NullPointerException' was thrown. 
06-17 22:50:59.674 E/mono-rt (4198): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x0000c] in /Users/builder/data/lanes/2923/52635947/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 
06-17 22:50:59.674 E/mono-rt (4198): at Java.Interop.JniEnvironment+InstanceMethods.CallVoidMethod (JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00084] in /Users/builder/data/lanes/2923/52635947/source/Java.Interop/src/Java.Interop/Java.Interop/JniEnvironment.g.cs:11643 
06-17 22:50:59.674 E/mono-rt (4198): at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00031] in /Users/builder/data/lanes/2923/52635947/source/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:26 
06-17 22:50:59.674 E/mono-rt (4198): at Android.Widget.ListPopupWindow.Show() [0x00000] in /Users/builder/data/lanes/2923/52635947/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Widget.ListPopupWindow.cs:1527 
06-17 22:50:59.674 E/mono-rt (4198): at PocketPacTracAndroid.Track.popupToSelectCourier (System.Collections.Generic.List`1 validationResults) [0x000a4] in C:\Projects\PocketPacTracAndroid\PocketPacTracAndroid\PocketPacTracAndroid\Track.cs:225 
06-17 22:50:59.674 E/mono-rt (4198): at PocketPacTracAndroid.Track.validateBarcode (System.String rawBarcode) [0x0014e] in C:\Projects\PocketPacTracAndroid\PocketPacTracAndroid\PocketPacTracAndroid\Track.cs:192 
06-17 22:50:59.674 E/mono-rt (4198): at PocketPacTracAndroid.Track.Barcode_KeyPress (System.Object sender, Android.Views.KeyEventArgs e) [0x0001c] in C:\Projects\PocketPacTracAndroid\PocketPacTracAndroid\PocketPacTracAndroid\Track.cs:88 
06-17 22:50:59.674 E/mono-rt (4198): at Android.Views.View+IOnKeyListenerImplementor.OnKey (Android.Views.View v, Keycode keyCode, Android.Views.KeyEvent e) [0x00018] in /Users/builder/data/lanes/2923/52635947/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Views.View.cs:2854 
06-17 22:50:59.674 E/mono-rt (4198): at Android.Views.View+IOnKeyListenerInvoker.n_OnKey_Landroid_view_View_ILandroid_view_KeyEvent_ (IntPtr jnienv, IntPtr native__this, IntPtr native_v, Int32 native_keyCode, IntPtr native_e) [0x0001c] in /Users/builder/data/lanes/2923/52635947/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Views.View.cs:2787 
06-17 22:50:59.674 E/mono-rt (4198): at (wrapper dynamic-method) System.Object:22b2513e-fc1d-45f2-938f-fbc85af3219a (intptr,intptr,intptr,int,intptr) 
06-17 22:50:59.674 E/mono-rt (4198): --- End of managed exception stack trace --- 
06-17 22:50:59.674 E/mono-rt (4198): java.lang.NullPointerException 
06-17 22:50:59.674 E/mono-rt (4198): at android.widget.PopupWindow.getMaxAvailableHeight(PopupWindow.java:1219) 
06-17 22:50:59.674 E/mono-rt (4198): at android.widget.ListPopupWindow.buildDropDown(ListPopupWindow.java:1090) 
06-17 22:50:59.674 E/mono-rt (4198): at android.widget.ListPopupWindow.show(ListPopupWindow.java:524) 
06-17 22:50:59.674 E/mono-rt (4198): at mono.android.view.View_OnKeyListenerImplementor.n_onKey(Native Method) 
06-17 22:50:59.674 E/mono-rt (4198): at mono.android.view.View_OnKeyListenerImplementor.onKey(View_OnKeyListenerImplementor.java:30) 
06-17 22:50:59.674 E/mono-rt (4198): at android.view.View.dispatchKeyEvent(View.java:7081) 
06-17 22:50:59.674 E/mono-rt (4198): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1358) 
06-17 22:50:59.674 E/mono-rt (4198): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1358) 
06-17 22:50:59.674 E/mono-rt (4198): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1358) 
06-17 22:50:59.674 E/mono-rt (4198): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1358) 
06-17 22:50:59.674 E/mono-rt (4198): at android.support.v4.view.ViewPager.dispatchKeyEvent(ViewPager.java:2567) 
06-17 22:50:59.674 E/mono-rt (4198): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1358) 
06-17 22:50:59.674 E/mono-rt (4198): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1358) 
06-17 22:50:59.674 E/mono-rt (4198): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1358) 
06-17 22:50:59.674 E/mono-rt (4198): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1358) 
06-17 22:50:59.674 E/mono-rt (4198): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1892) 
06-17 22:50:59.674 E/mono-rt (4198): at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1369) 
06-17 22:50:59.674 E/mono-rt (4198): at android.app.Activity.dispatchKeyEvent(Activity.java:2356) 
06-17 22:50:59.674 E/mono-rt (4198): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1819) 
06-17 22:50:59.674 E/mono-rt (4198): at android.view.ViewRootImpl.deliverKeyEventPostIme(ViewRootImpl.java:3575) 
06-17 22:50:59.674 E/mono-rt (4198): at andro 

誰もが、私はこのエラーが何であるかを理解する助けてください可能性があり、それを修正する方法をした場合(つまり、GETポップアップウィンドウは私の断片から作業しています)。私は私の目標を達成するための他の提案にもオープンしています。

ありがとうございます!

答えて

0

アンカーをListPopupWindowに設定する必要があります。このようなアンカーとして任意のビューを設定することができます -

popup.setAnchorView(<your_view_here_to_which_you_want_it_to_be_anchored>); 
+0

これは完璧に機能しました!違いは、Xamarinはプロパティとしていくつかのものを公開します。だから、 –

+0

の代わりに、間違ったボタンを押してください。したがって、 'popup.setAnchorView(view)'の代わりに 'popup.SetAnchorView = view;'でした。また、ViewをView Viewとしてグローバルに定義してから、onCreateViewで次のように割り当てる必要がありました:public override View OnCreateView(LayoutInflaterインフレータ、ViewGroupコンテナ、Bundle savedInstanceState) { view = inflater.Inflate(Resource.Layout .Track、container、false); ' –

関連する問題