Comparing string array xml

153 views Asked by At

I'm trying to take two "string array" from XML file, and make a guessing game First of all showing random symbol on screen from string array "first" あ this symbol is equal "a" from the "second" and so on. User has to guess what kind of letter does that symbol refers to. Since I'm going to make a lot of these arrays, anyone has an Idea or peace of code as an example, other options are also fine.

   <string-array name="first">
        <item>あ</item>
        <item>い</item>
        <item>う</item>
        <item>え</item>
        <item>お</item>
    </string-array>
    <string-array name="second">
        <item>a</item>
        <item>b</item>
        <item>c</item>
        <item>d</item>
        <item>e</item>
    </string-array>
2

There are 2 answers

0
Tadej On BEST ANSWER

Alternatively, you can do this:

static String[] sFirst;
static String[] sSecond;

static void load(final Context context) {
  sFirst = context.getResources().getStringArray(R.array.first);
  sSecond = context.getResources().getStringArray(R.array.second);
}

// Somewhere along the way, an index from the first array is chosen.
int selected = 0;

String weirdLetter = sFirst[selected];
String normalLetter = sSecond[selected];

// Do stuff with both letters
0
betteroutthanin On

What about using a HashTable to save the pairs:

Hashtable<Character, Character> pair = new Hashtable<Character, Character>();
pair.put('a', 'あ');