0

Trying to make custom spinner. And get the list for that spinner from resources

As I understand to do that I need to call

getResources().getStringArray(R.array.list_items)

But the problem is in the logic of adapter I need to add one item at the end to make it as a hint. But in String[] I cant just do that. I can do that just in ArrayList.

So what is the best solution for that? Do I need to convert String[] to ArrayList but how to do that? Or what?

Zohaib Amir
  • 3,482
  • 2
  • 11
  • 29
Bo Z
  • 2,359
  • 1
  • 13
  • 31
  • 2
    Possible duplicate of [How to add elements of a string array to a string array list?](https://stackoverflow.com/questions/12853595/how-to-add-elements-of-a-string-array-to-a-string-array-list) – Zohaib Amir Jul 23 '19 at 15:00
  • @ZohaibAmir partially you are right. But the main question is there any particular good practice to use list from RESOURCES of android in custom spinner. I might need to change title. – Bo Z Jul 23 '19 at 15:48

2 Answers2

1

From your comment, it seems you are asking if there is any way to either directly read xml array or a "better" way to get ArrayList. If you look at Resources class, there is no such API. Moreover ArrayList uses Array as foundation so usual way of loading array first and then wrapping it in ArrayList is the most efficient way.

Zohaib Amir
  • 3,482
  • 2
  • 11
  • 29
0

You can simply do like this:

new ArrayList(Arrays.asList(getResources().getStringArray(R.array.list_items)));
ArbenMaloku
  • 548
  • 4
  • 15