0

Making spinner with custom dropdown list

I want to make a Spinner in android which will have the following dropdown list style:

enter image description here

My onCreate method does

 ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
                this, R.array.day, android.R.layout.simple_spinner_item);

and

setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)

to make the previous image's spinner dropdown list.

  protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

       Spinner spinner = (Spinner) findViewById(R.id.spinner);

        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
                this, R.array.day, android.R.layout.simple_spinner_item);

        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);

    }

I followed the instructions from this site . But I don't get the same dropdown list. The setDropDownViewResource and the adapter have no effect.

enter image description here

The only difference i find with the instructions is that the example's style is "android:Theme.Light", while my theme style is Theme.AppCompat.Light. So, i wonder if the AppCompat is the problem.

yuva ツ
  • 3,707
  • 9
  • 50
  • 78
zoe vas
  • 281
  • 9
  • 25
  • I dont see the difference between the two screenshots except for the theme change. Why are you saying that adapter has no effect? – bhargavg Aug 12 '14 at 11:15
  • 1
    the 1st image is actually screenshot of `dialog` with single choice option, the second image is the `spinner` image with drop down layout set to the `adpater` – Akhil Jain Aug 12 '14 at 11:17
  • There are not green radio buttons and the dropdown list is not shown as dialog with title as in the example. – zoe vas Aug 12 '14 at 11:18
  • Yes it seems like a dialog but if you see this link http://www.tuicool.com/articles/emaeme, you will see that spinner is used. – zoe vas Aug 12 '14 at 11:21
  • Check this one : http://stackoverflow.com/questions/16694786/how-to-customize-a-spinner-in-android or http://stackoverflow.com/questions/16587181/how-to-change-style-of-custom-spinner-in-android – Haresh Chhelana Aug 12 '14 at 11:29

1 Answers1

0

try this to solve your issue

xml:

<Spinner
        android:id="@+id/spinner1"
        android:layout_width="275dp"
        android:layout_height="50dp"
        android:layout_gravity="center"
        android:spinnerMode="dropdown"
        style="@android:style/Widget.Spinner"
        android:layout_marginTop="20dp" />

code:

ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.day, android.R.layout.simple_spinner_item);


adapter.setDropDownViewResource(android.R.layout.select_dialog_singlechoie);
spinner.setAdapter(adapter);
Anirudh Sharma
  • 7,968
  • 13
  • 40
  • 42
PLP
  • 714
  • 3
  • 13