2

I'm new to Android programming, so please let me know if I'm doing anything stupid. However, I currently have an array String[] gamesList that is dynamically generated from a database.

I want to use each element of an array in a Spinner, but the Adapter has a method signature of (Context, int, int). The first and third inputs I can do, but the second is asking for the id of a resource; but I don't have a R.array.someRandomName resource, I only have a local array.

Is there some way to make the array a resource, or if not, how do I do this?

Anonymous
  • 25
  • 3

3 Answers3

1

Create an ArrayAdapter out of your array (read this), then call the Spinner's setAdapter() method.

dmon
  • 30,048
  • 8
  • 87
  • 96
0

Making the array into a resource is an unnecessary and unconventional step. Instead, you should look at this previous question: Android - configure Spinner to use array

Community
  • 1
  • 1
Jodes
  • 14,118
  • 26
  • 97
  • 156
0

If the list of strings is fixed, you can use a String Array. You can also use an ArrayAdapter for dynamically generated arrays of strings.

Ted Hopp
  • 232,168
  • 48
  • 399
  • 521