0

I have a spinner which is created programmatically like this:

spinnerLogger = new Spinner(context);
    spinnerLogger.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    SpinnerAdapter spinnerAdapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_dropdown_item, spinnerNames);
    spinnerLogger.setAdapter(spinnerAdapter);

in my code I also use xml created spinners which use a style to make sure the user understands they are spinners:

<Spinner
        android:layout_width="90dp"
        android:layout_height="wrap_content"
        android:id="@+id/spinnerHour"
        android:spinnerMode="dropdown"
        style="@style/Widget.AppCompat.Spinner.Underlined" />

I want to apply the Widget.AppCompat.Spinner.Underlined style to the programmatically created spinner but can't seem to find how I can achieve this.

I tried by creating an xml containing only a spinner with the right style (xml's name is spinner_underlined and it's located in the layout folder):

<?xml version="1.0" encoding="utf-8"?>
    <Spinner android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/spinner"
    xmlns:android="http://schemas.android.com/apk/res/android"
    style="@style/Widget.AppCompat.Spinner.Underlined"/>

when i try to apply this using

SpinnerAdapter spinnerAdapter = new ArrayAdapter<>(context, android.R.layout.spinner_underlined, spinnerNames);

it gives me a cannot resolve symbol 'spinner_underlined' error

dec0yable
  • 87
  • 13
  • Do you actually have an xml layout named `spinner_underlined`? Located possibly in your layout folder? If so, try to remove `android.` there. – AL. Apr 29 '16 at 06:53
  • what is android.R.layout.spinner_underlined you had any reference for this plz explain it. i think u never define spinner_underlined style in style.xml?? – Nowshad Apr 29 '16 at 06:57
  • try this android.R.layout.simple_spinner_item instead of android.R.layout.spinner_underlined let see what happened after that then we move further....! – Nowshad Apr 29 '16 at 07:06
  • I tried replacing the `android.R.layout.simple_spinner_dropdown_item` with `spinner_underlined` and it changed the dropdown items to the right style but not the spinner itself – dec0yable Apr 29 '16 at 07:12
  • here is for spinner style you will find more style example try this [link](http://www.broculos.net/2013/09/how-to-change-spinner-text-size-color.html#.VyMKgvkrKzc) – Nowshad Apr 29 '16 at 07:19
  • dont do any thing extra just focus on style! – Nowshad Apr 29 '16 at 07:20
  • I don't get the info in the link. in the link the spinner is created in xml. The spinner I use is created porgrammatically. so I already set a spinneradapter to the spinner and I don't think you can set multiple adapters? – dec0yable Apr 29 '16 at 07:32
  • ohhh sorry that was wrong link try [this one](http://stackoverflow.com/questions/30712235/spinner-dropdown-arrow) hope it will help you! – Nowshad Apr 29 '16 at 07:40
  • really sorry but i don't see where he applies the style to the spinner itself. All i'm trying to do is taking a style which exists in android (`@style/Widget.AppCompat.Spinner.Underlined`) and set it to a programmatically made spinner. Does it really have to be this hard? – dec0yable Apr 29 '16 at 07:51

1 Answers1

0

You need change to R.layout.... not android.R.layout....

mdtuyen
  • 4,470
  • 5
  • 28
  • 50
  • where do I set this? because it's asking for a type layout in the adapter – dec0yable Apr 29 '16 at 06:56
  • @dec0yable Do you not know as to why the `ArrayAdapter` is looking for a layout parameter? – AL. Apr 29 '16 at 07:00
  • sorry, I update answer, I cannot find spinner_underlined layout on android library. I think that is your layout. You should import your R.java to class file – mdtuyen Apr 29 '16 at 07:00
  • Sorry i'm a self taught android (i don't even dare to call myself a programmer) user so i don't know what you mean by that – dec0yable Apr 29 '16 at 07:18