0

The closest I could find on S.O. is this but it doesn't answer it.

It specifies here how to make a resource reference for a string, i.e. @string/string_name but further down under String Array in the documentation, it gives no option under Resource Reference for referencing the string array in XML like it does further up for String.

Progster219
  • 85
  • 10
  • It simply isn't possible but there are some workarounds that could work for you, like this one here: https://stackoverflow.com/questions/30465202/how-do-i-call-string-array-value-in-xml-layout – Timo Salomäki Sep 04 '17 at 16:53
  • It would be like `@array/string_array_name`, but the attribute you use it for has to be able to take an array. – Mike M. Sep 04 '17 at 16:58

1 Answers1

0

It's unclear what element you are trying to load the array into...

ListView has android:entries that accepts @array/ resource.

However, I find that adding adapters in the code makes more sense. ArrayAdapter.createFromResource allows you to use an a String Array XML resource to load either a Spinner or a ListView using R.array in Java code.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • I think Mike M. basically answered my question, i.e. what I was looking for was `@array/string_array_name` for use in a ListView. I guess based on the first comment and what i've seen as these adapters basically being a workaround for the `@array` feature not being available previously, or am I totally off on that assessment? – Progster219 Sep 05 '17 at 02:54
  • It would be nice if `@array` could be used like that, but a ListView in the XML does not know the layout used by the adapter (or if there is an adapter available) at the inflation step of that parent layout – OneCricketeer Sep 05 '17 at 02:56
  • So are you saying basically you can only get a crude output? I.e. I tried this http://theopentutorials.com/tutorials/android/listview/android-creating-and-populating-listview-items-in-xml/ and it "works" (list items are shown without having to program an adapter) but are you saying it really doesn't work in some way? – Progster219 Sep 05 '17 at 03:01
  • Ah, yes, I forgot about that attribute – OneCricketeer Sep 05 '17 at 05:26