-1
<string id="I want To Get This">and this</string>
<string id="I want To Get This">and this</string>
<string id="I want To Get This">and this</string>

How to get the value

Jyotish Biswas
  • 674
  • 5
  • 11
  • you're asking how to get the keys and values out of an xml string resource, correct ? – a_local_nobody Jul 28 '20 at 07:27
  • Yes and add it list map – Programming Help Jul 28 '20 at 07:34
  • Does this answer your question? [How to read XML using XPath in Java](https://stackoverflow.com/questions/2811001/how-to-read-xml-using-xpath-in-java) – Tomas Ivan Jul 28 '20 at 08:28
  • You have to read https://stackoverflow.com/help/how-to-ask first. Your question is clearly bad. This is site where you can ask for advice, hint or small block of code. But you have to show us some effort and not only ask for complete solution / code. – Tomas Ivan Jul 28 '20 at 08:31

1 Answers1

1

To get the value from String Resource you use

String stringToCompare= getString(R.string.my_custom_id);

After that you can add that value to a list

myList.add(value)

Now if you say all similar I suppose you mean equal values or at least same characters. For that you could iterate over all the string values via reflection

for (Field field : R.string.class.getDeclaredFields()) {
 if (Modifier.isStatic(field.getModifiers()) && !Modifier.isPrivate(field.getModifiers()) && field.getType().equals(int.class)) {
   try {
     if (field.getName().toLoweCase().equals(stringToCompare.toLowerCase())) {
       int id = field.getInt(null);
       myList.add(getString(id))
     }
   } catch (IllegalArgumentException e) {
      // ignore
   } catch (IllegalAccessException e) {
     // ignore
    }
  }
}

Or can find another way of doing that iteration here How to easily iterate over all strings within the "strings.xml" resource file?

dreinoso
  • 1,479
  • 17
  • 26