I am trying to get string value from string file like this:
var language = arrayListOf<String>(
R.string.All_Categories.toString(),
)
but it shows an Int rather than a string like this:
What am I doing wrong?
The issue is you are doing toString on the generated reference. You should instead use R.array.All_Categories if that is the name of your referenced array. For example, you have the following in the resources file.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="my_books">
<item>Scala Cookbook</item>
<item>Play Framework Recipes</item>
<item>How I Sold My Business: A Personal Diary</item>
<item>A Survival Guide for New Consultants</item>
</string-array>
</resources>
This is how you would want to read it in the code.
Resources res = getResources();
String[] myBooks = res.getStringArray(R.array.my_books);
Kotlin code example in fragment:
val res: Resources = resources
val myBooks: Array<String> = res.getStringArray(R.array.my_books)
You can use .toList() on the Array<String> to convert it to a collections object like the arrayListOf<String> expected by you.