Question

I am trying to customize the default appearance of a Spinner item.

I have defined a layout in a file by the name of :

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textColor="#ff0000"
    android:textSize="20sp" />

And here when initializing the spinner I am trying to assign this layout to it:

ArrayAdapter<String> nearByLocationsAdpt = new ArrayAdapter<String>(this, android.R.layout.spinner_item_layout,nearByLocationsArray);
  • But it keeps saying that spinner_item_layout cannot be resolved or is not a field however it is present in the layout folder?
  • Another related question is it possible to view and edit the default spinner layout xml file i.e. android.R.layout.simple_spinner_item
Was it helpful?

Solution

The problem is this:

android.R.layout.spinner_item_layout

You are using the default layout. You have to supply the one you created instead. Depending on the how you named your layout that would be something like this:

R.layout.my_spinner_item
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top