I try to create an Expandable ListView in a Fragment and right away the question, in all the guides, the arrays for the names of groups and lists are used like this:

// названия компаний (групп) String[] groups = new String[] {"HTC", "@Samsung", "@LG"}; // названия телефонов (элементов) String[] phonesHTC = new String[] {"Sensation", "Desire", "Wildfire", "Hero"}; String[] phonesSams = new String[] {"Galaxy S II", "Galaxy Nexus", "Wave"}; String[] phonesLG = new String[] {"Optimus", "Optimus Link", "Optimus Black", "Optimus One"}; 

Is there an option to put them in string resources, so that when translating the application into other languages, you don’t have to face this problem? Tried to create in string resources

 <string-array name="1-10"> <item>Раз</item> <item>Два</item> <item>Три</item> <item>Четыре</item> <item>Пять</item> <item>Шесть</item> <item>Семь</item> <item>Восемь</item> <item>Девять</item> <item>Десять</item> </string-array> 

but the application crashes, crashes, indicating that the array is empty.

    1 answer 1

    Apparently, you first need to get an array object from the resources and transfer it to the adapter, and not directly refer to the resources in the adapter:

      String[] group1 = getResources().getStringArray(R.array.group1); 

    similarly for other string arrays in resources.

    PS: in the same way, the name of an array in resources (and, in general, variables in Java) must begin with letters and contain a limited set of characters (Latin letters, numbers, $ and _ signs). Name 1-10 does not fit

    • about the name of the arrays in the course, for example wrote here. - Armen Mkhitaryan