android


Issues with custom layout for spinner for Android


I know there is a lot of discussions around custom spinners, however I am still not able to grasp how to do it. What I want is a spinner with a custom layout for the dropdown items and a custom layout for the spinner when not "activated". When the app runs the spinner have the specific layout(when not activated) however when activated it chrashes, which makes me believe there might be a problem with the xml. But here it goes(btw I use mono and c#);
I create a ArrayAdapter for the spinner this way, where I set a layout for the spinner Resource.Layout.SpinnerView and for the dropdown 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" />
And I add the spinner to the activity layout with the following 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"
/>
I tried to use the the samelayout Resource.Layout.SpinnerView for both and then the app would not chrash - however then i have not the correct custom layout for the drop down items.
I hope someone can help me and point me in the right direction.
---UPDATE---
The following is log when i chrashes and it seems to be an nullpointer which I dont fully understand.
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)
Okay guys I solved it myself and it might be a newbie mistake I am not sure. I needed to make changes to my layout xml files. The id for the textview needs to be the same or else it results in a null pointer exception.
I have changed my xml to the following
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:id="#+id/spinnertext"
android:layout_width="wrap_content"
android:layout_centerInParent="true"
android:background="#drawable/down"
android:gravity="center"
android:layout_height="wrap_content" />
Maybe in your Resource.Layout.SpinnerRow the textview have to be checkedtextview

Related Links

How to use PercentRelativeLayout in a CollapsingToolbarLayout?
could not find wglGetExtensionsStringARB
ImageView not updated after device is switched off an on again, while app is on top
onScrolled RecyclerView not triggered after DataSet changes
Open global search as overlay
take the activity content to dialog
Xamarin Android SDK Location
Android - Restoring App Widgets on Reboot or Crash
Android global scope String returns null
What is Virtual Reality View(vr view) in android? [closed]
Run GcmListenerService New Process
xamarin NavigationView gives error no resource found for app:headerLayout
Buttons getting cut off in landscape rotation (Android XML)
getSupportFragmentManager in Service,Android studio
Activity has leaked window com.android.internal.policy.PhoneWindow$DecorView{2d637e8 V.E… R… 0,0-768,293} that was originally added here
How sort recyclerview by data

Categories

HOME
sonarqube
swt
sh
error-handling
opendj
access
static-site
rom
okhttp
arangodb
fosrestbundle
dkim
mxgraph
endpoint
intercom
easyphp
symbols
breadth-first-search
gulp-watch
mount
errbot
sqlpackage
send
quickfixj
android-gridview
twos-complement
carriage-return
sharding
indy10
arduino-ide
apic
metawidget
unordered-map
escpos
android-ibeacon
sharp-snmp
geotiff
openblas
reindex
edit
ngmaterial
avx
stripe-connect
winusb
microstation
swizzling
nservicebus5
phpwebsocket
jparsec
character-replacement
boomerang
grgit
xvim
google-books
page.js
dock
rpart
haskell-warp
dronekit-android
mirror
matlab-deployment
node-serialport
zend-currency
mmwormhole
webfinger
genymotion-call
tweenlite
mdichild
wxformbuilder
dsym
cfcache
xmltodict
ora-06550
scriptaculous
bin
notorm
embedded-fonts
hidapi
epiceditor
midlet
qtconcurrent
subproject
android-holo-everywhere
rmdir
multiplatform
svk
timertask
rowlex
tabpanel
spread
feasibility
soappy
contentpresenter

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App