'Difference between android.R.layout.simple_spinner_dropdown_item and android.R.layout.simple_spinner_item

Here's a sample code of using spinner in android :

Spinner spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.gender_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);

I have understood that we need to specify a layout for the datarows in the adapter

But why again using setDropDownViewResource() method. I mean what does this function do and also tell me how it is different from the constructor of the ArrayAdapter.

I have gone through the documentation, but didn't understand completely.



Solution 1:[1]

Here's is the difference - See below images

simple_spinner_item

Simple_Spinner

If you're using your spinner with spinner.setAdapter(adapter); directly in your code, your spinner will looks like above image.

But, if you're using adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); in your code, it'll show your spinner like below image where the spinner items will shown with radio buttons.

simple_spinner_dropdown_item

enter image description here

Solution 2:[2]

Normally the difference between android.R.layout.simple_spinner_dropdown_item and android.R.layout.simple_spinner_item is

Simple spinner Dropdown view

Simple spinner dropdown view

Simple spinner view

simple spinner view

Solution 3:[3]

The difference is as below:

  1. simple_spinner_item is the layout of each drop-down item on the spinner list.
  2. And inorder to house these x number of drop-down items, the layout required is simple_spinner_dropdown_item

Solution 4:[4]

use adapter1.setDropDownViewResource(android.R.layout.select_dialog_singlechoice);

  1. select_dialog_singlechoice -- to show radio button
  2. select_dialog_multichoice --- multiple select
  3. simple_spinner_dropdown_item --- without radio button

just change this setDropDownViewResource line from above choice.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Community
Solution 2 code_finder
Solution 3 Chas. Owens
Solution 4 DharmanBot