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.

2
  • It simply isn't possible but there are some workarounds that could work for you, like this one here: stackoverflow.com/questions/30465202/… Commented Sep 4, 2017 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. Commented Sep 4, 2017 at 16:58

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

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?
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
So are you saying basically you can only get a crude output? I.e. I tried this theopentutorials.com/tutorials/android/listview/… 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?
Ah, yes, I forgot about that attribute

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.