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 restrict or permit people from using your Content provider
How to call another screens from one screen that have seven buttons
Memory issue in my android
Auto complete address search Android Map v2 [closed]
Android - What is happens after calling startScan method of WifiManager
How to scale imageview image to specific size?
ClassCastException: SoapPrimitive can't be cast to SoapObject (Apparently there is no SoapPrimitive here)
Delete ParseObject matching Query
Simple Android app crashes when calling Button Method
Android diagonal triangle buttons
Android - communicate with the backend
Access to view elements in fragments
how to override on activityResult in android
how to create a countdown timer in android using thread?
How to get Text from Parent div only using Jsoup in Android
How to revert a View back to height of “wrap_content” after animating it to be 0dp?

Categories

HOME
sonarqube
algorithm
cobalt
time-complexity
object
jmx
pascal
hessian
saml-2.0
vscode-extensions
onclick
interpolation
google-cloud-datalab
jtextpane
nfs
pattern-matching
commonjs
resultset
activecollab
emoji
opengl-es-3.0
magnetic-cards
red5
asp.net-mvc-viewmodel
production
sse
poedit
springfox
gulp-watch
named-entity-recognition
ios10.2
imageresizer
maze
bulletphysics
jasmine-node
delimiter
errbot
tizen-tv
failover
testcomplete
scatter3d
paragraph
utorrent
linkedhashmap
carriage-return
parse-tree
google-knowledge-graph
flatmap
protein-database
verifiable-c
loading
visa
http-request
avcapturedevice
memory-mapping
flask-login
serde
fclose
openblas
magic-draw
semantic-logging
oracleclient
ngmaterial
avx
bbpress
restore
juice-ui
rmongo
change-tracking
usart
pure-css
actor-platform
mta
udpclient
qiime
cassia
nio2
directdraw
custom-errors
iokit
rate-limiting
zen-cart
page.js
text-search
lasso
rdflib
botan
typeconverter
git-ftp
osc
dot.js
phpldapadmin
contrast
strawberry-perl
malformedurlexception
tinyxml
dot42
solace-mq
gpars
jquery-1.9
mkv
pstack
fitbounds
workflow-services
android-holo-everywhere
xcelsius
google-floodlight
twitterizer
qglwidget
django-piston
mathematical-notation
pbcopy

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