我知道圍繞自定義微調控制器進行了很多討論,但是我仍然無法掌握如何去做。我想要的是一個微調控制器,它具有下拉菜單項的自定義佈局和未激活時微調控件的自定義佈局。當應用程序運行時,微調器具有特定的佈局(當未激活時),但是當它被激活時會崩潰,這使我相信xml可能存在問題。但它在這裏(順便說一句,我使用單聲道和C#);針對Android微調控制檯的自定義佈局問題
我創建一個ArrayAdapter的微調這樣,我在那裏的微調Resource.Layout.SpinnerView和下拉Resource.Layout.SpinnerRow設置佈局:
ArrayAdapter spinnerArrayAdapter = new ArrayAdapter(this.Context,Resource.Layout.SpinnerView,Resource.Id.spinnertext,_listOfUmbracoItems);
spinnerArrayAdapter.SetDropDownViewResource(Resource.Layout.SpinnerRow);
Resource.Layout.SpinnerView:
<?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/dk.appsfabrikken.cmsapp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:src="@drawable/eduvalg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerInside"
android:padding="0.0dp"
android:layout_alignParentTop="true"
android:id="@+id/backgroundimageview" />
<TextView
android:id="@+id/spinnertext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="0.0dp" />
</RelativeLayout>
Resource.Layout.SpinnerRow:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/down"
android:gravity="center"
android:layout_height="wrap_content" />
而且我微調添加到活動佈局與下面的XML:
<CmsApp.Droid.Controls.UmbracoSpinner
android:id="@+id/spinnerMenu"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:drawSelectorOnTop="true"
/>
我試圖用的samelayout Resource.Layout.SpinnerView兩個,然後應用程序不會chrash - 不過後來我就沒有正確的自定義下拉項目的佈局。
我希望有人能幫助我,並指出我的方向正確。
---更新--- 以下是日誌當我崩潰,它似乎是一個我不完全理解的空指針。
04-26 22:45:47.423: E/AndroidRuntime(11536): FATAL EXCEPTION: main
04-26 22:45:47.423: E/AndroidRuntime(11536): java.lang.NullPointerException
04-26 22:45:47.423: E/AndroidRuntime(11536): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:353)
04-26 22:45:47.423: E/AndroidRuntime(11536): at android.widget.ArrayAdapter.getDropDownView(ArrayAdapter.java:376)
04-26 22:45:47.423: E/AndroidRuntime(11536): at android.widget.Spinner$DropDownAdapter.getDropDownView(Spinner.java:329)
04-26 22:45:47.423: E/AndroidRuntime(11536): at android.widget.Spinner$DropDownAdapter.getView(Spinner.java:325)
04-26 22:45:47.423: E/AndroidRuntime(11536): at android.widget.AbsListView.obtainView(AbsListView.java:1315)
04-26 22:45:47.423: E/AndroidRuntime(11536): at android.widget.ListView.measureHeightOfChildren(ListView.java:1198)
04-26 22:45:47.423: E/AndroidRuntime(11536): at android.widget.ListView.onMeasure(ListView.java:1109)
04-26 22:45:47.423: E/AndroidRuntime(11536): at android.view.View.measure(View.java:8171)
04-26 22:45:47.423: E/AndroidRuntime(11536): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
04-26 22:45:47.423: E/AndroidRuntime(11536): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
04-26 22:45:47.423: E/AndroidRuntime(11536): at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
04-26 22:45:47.423: E/AndroidRuntime(11536): at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
04-26 22:45:47.423: E/AndroidRuntime(11536): at android.view.View.measure(View.java:8171)
04-26 22:45:47.423: E/AndroidRuntime(11536): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
04-26 22:45:47.423: E/AndroidRuntime(11536): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
04-26 22:45:47.423: E/AndroidRuntime(11536): at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
04-26 22:45:47.423: E/AndroidRuntime(11536): at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
04-26 22:45:47.423: E/AndroidRuntime(11536): at com.android.internal.widget.WeightedLinearLayout.onMeasure(WeightedLinearLayout.java:60)
04-26 22:45:47.423: E/AndroidRuntime(11536): at android.view.View.measure(View.java:8171)
04-26 22:45:47.423: E/AndroidRuntime(11536): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
04-26 22:45:47.423: E/AndroidRuntime(11536): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
04-26 22:45:47.423: E/AndroidRuntime(11536): at android.view.View.measure(View.java:8171)
04-26 22:45:47.423: E/AndroidRuntime(11536): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
04-26 22:45:47.423: E/AndroidRuntime(11536): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
04-26 22:45:47.423: E/AndroidRuntime(11536): at android.view.View.measure(View.java:8171)
04-26 22:45:47.423: E/AndroidRuntime(11536): at android.view.ViewRoot.performTraversals(ViewRoot.java:801)
04-26 22:45:47.423: E/AndroidRuntime(11536): at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
04-26 22:45:47.423: E/AndroidRuntime(11536): at android.os.Handler.dispatchMessage(Handler.java:99)
04-26 22:45:47.423: E/AndroidRuntime(11536): at android.os.Looper.loop(Looper.java:123)
04-26 22:45:47.423: E/AndroidRuntime(11536): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-26 22:45:47.423: E/AndroidRuntime(11536): at java.lang.reflect.Method.invokeNative(Native Method)
04-26 22:45:47.423: E/AndroidRuntime(11536): at java.lang.reflect.Method.invoke(Method.java:521)
04-26 22:45:47.423: E/AndroidRuntime(11536): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-26 22:45:47.423: E/AndroidRuntime(11536): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-26 22:45:47.423: E/AndroidRuntime(11536): at dalvik.system.NativeStart.main(Native Method)
我只是給它一個嘗試,它確實不會導致任何不同。當我激活微調器時,該應用程序仍然崩潰。但非常感謝你的建議。 – Bjarke 2012-04-28 05:20:16
當應用程序崩潰時,你能給我們一些日誌嗎? – digulino 2012-04-28 14:38:52
我有postet完整的日誌時例外 - 謝謝 – Bjarke 2012-04-30 08:59:11