0

I have a custom simple_spinner_item and simpel_spinner_dropdown_item. I am setting these using the following code:

adapter = new ArrayAdapter<Integer>(context, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);

However, the custom style is not applied. How can I fix this?

I am overriding the default android dropdown items in my style.

However, it works if I create a new Adapter that extends ArrayAdapter and override getDropdownResource.

barq
  • 3,681
  • 4
  • 26
  • 39

3 Answers3

1

Try to remove "android" like this :

adapter = new ArrayAdapter<Integer>(context, R.layout.simple_spinner_item);
adapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item);
Jonas
  • 88
  • 7
  • I am overriding the default android dropdown items in my style. – barq Feb 18 '15 at 17:21
  • @barq Even though you're overriding that, but you shouldn't write `android.R` at there. You should address your own layout file instead. Some thing like `your.package.name.R.layout.your_layout_file` – frogatto Feb 18 '15 at 17:28
  • I don't understand how that would be possible, because I have a style that contains the attributes, not an xml file. – barq Feb 18 '15 at 17:32
  • It doesn't find package.R.layout.simple_spinner_item or R.layout.simple_spinner_item. But I am importing the R in my own package. – barq Feb 18 '15 at 17:39
0

Instead of android.R.files you have to include your project R.files for custom layout.

Surender Kumar
  • 1,123
  • 8
  • 15
0

This might help. Setting parent theme worked for me. for separate item and dropdown file. https://stackoverflow.com/a/17213328/7735068

Willey Hute
  • 939
  • 13
  • 18