Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android string-array to Array

Tags:

arrays

android

This time I want to get an array-list element from strings.xml and convert it to an array (String[], List or whatever can later be used to read the elements or the total size). I am trying with List<String> MathFormulas = Arrays.asList(getResources().getStringArray(R.id.StringArray)); but the application crashes, so this must be the wrong way of doing it. Some help? Thanks!

like image 830
ali Avatar asked Apr 23 '12 17:04

ali


People also ask

What is string array in Android?

Note: A string array is a simple resource that is referenced using the value provided in the name attribute (not the name of the XML file). As such, you can combine string array resources with other simple resources in the one XML file, under one <resources> element. file location: res/values/filename.xml.

How do you add a string array to a string array in Java?

Create an empty String Buffer object. Traverse through the elements of the String array using loop. In the loop, append each element of the array to the StringBuffer object using the append() method. Finally convert the StringBuffer object to string using the toString() method.


1 Answers

you can convert it to string arrar as below::

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

or

List<String> MathFormulas = Arrays.asList(getResources().getStringArray(R.array.StringArray));
like image 61
Shankar Agarwal Avatar answered Sep 22 '22 02:09

Shankar Agarwal