Error string-array android

0

In the android resources file I have a <string-array name="system"> with two items, what I want is to call it in a java class that extends from RecyclerView.Adapter to fill a string[] , in the following way:

String [] arregloFiguras=Resources.getSystem().getStringArray(R.array.system);

When executing it does not throw any errors, but the application does not deploy, an alert indicates that the app is damaged How can I fill string[] = {} with string values from the resource folder? thanks.

    
asked by Jeison Gonzalez 02.02.2018 в 05:19
source

2 answers

0

I was not very specific, but here what I needed and how to solve it. This is the code of the string-array that I wanted to recover.

<string name="circulo">Circulo</string>
<string name="ovalo">Óvalo</string>
<string name="cuadrado">Cuadrado</string>
<string name="rectángulo">Rectángulo</string>
<string name="libre">Dibujo Libre</string>

    <string-array name="nombresFiguras">
    <item>@string/circulo</item>
    <item>@string/ovalo</item>
    <item>@string/cuadrado</item>
    <item>@string/rectángulo</item>
    <item>@string/libre</item>
</string-array>

and in the java class I had to do this.

first declare.

String[] arregloFiguras;
String[] arreglo;

and in the constructor of the class, which in this case extends from RecyclerView.Adapter

   public RecyclerAdapter(Context context)

{     this.context = context;     inflater = LayoutInflater.from (context);     arrayFigures = context.getResources (). getStringArray (R.array.Figurablennames);     array = context.getResources (). getStringArray (R.array.nombreDescripciones); }

    
answered by 02.02.2018 в 17:51
-1

Resources.getSystem() returns system resources, not the application:

Android docs:

  

Resources.getSystem() - Returns a resource object   global shares that provides access only to the resources of the   system (not application resources) and is not configured for the   current screen (can not use dimension units, does not change according to   the orientation, etc.).

To achieve what you want you have to use the instance Resource of Context :

String[] myArray = context.getStringArray(R.array.my_array)
    
answered by 02.02.2018 в 13:45