0

This is part of my string.xml file on an application that I'm trying to create:

<array name="users">
    <item>
        <user_name>u1</user_name>
        <password>p1</password>
        <email>aaa@aaa</email>
    </item>
    <item>
        <user_name>u2</user_name>
        <password>p2</password>
        <email>bbb@bbb</email>
    </item>
    <item>
        <user_name>u3</user_name>
        <password>p3</password>
        <email>ccc@ccc</email>
    </item>
</array>

I have a problem reading the "users" two-dimensional array into a two-dimensional array on the java file. I've already created a class name "User" for the array. I'm quite stuck here. Can anybody give me a hand? Thanks

Lukas Knuth
  • 25,449
  • 15
  • 83
  • 111
Itzick Binder
  • 175
  • 1
  • 4
  • 18

2 Answers2

0

strings.xml is not for what you are trying to do here. It is supposed to have all strings that are displayed to the user to provide multi-language support.

If you want to store your app's domain data to XML file, you can create one in the assets folder and read it.

Mus
  • 1,860
  • 2
  • 16
  • 19
0

It's ok. I've solved it. Here is my code:

String[] userArray = getResources().getStringArray(R.array.users);
User[] arr = new User[3];
for(int i=0 ; i<userArray.length ; i++)
arr[i] = new User(userArray[i]);

and this is my "User" class constructor:

public User(String str)
{
    int num;
    str = str.substring(1);
    num = str.indexOf(' ');
    user_name = str.substring(0,num);
    String substr = str.substring(num+1);
    num = substr.indexOf(' ');
    password = substr.substring(0,num);
    email = substr.substring(num+1);
}

In that way I get an array of "User".

Itzick Binder
  • 175
  • 1
  • 4
  • 18