Good day, i will try to explain my problem as best as i can. i have in one of my class, getters and setters for a string object. Now in my getString() method, i am trying to compare the string to a string-array of items in my String.xml to see if any of the elements in the string-array file matches the given string and return that matched item element in the string array.
I have something like this so far:
for setPlace():
public void setPlace(String place) {
this.place = place;
}
for getPlace():
public String getPlace() {
//am stuck here and not sure how to compare this and return the correct item
if(place.equals(context.getResources().getStringArray(R.array.myPlacesArray))){
//return context.getResources().getString();
}
my Strings.xml file:
<string-array name="myPlacesArray">
<item>@string/myplace1</item>
<item>@string/myPlace2</item>
<item>@string/myPlace3</item>
</string-array>
<string name="myplace1">home</string>
<string name="myplace2">office</string>
<string name="myplace3">gym</string>
the reason i have to do this, is because it has different locales(languages) values and it would be a lot easier than writing a huge list of if/else or switch statements for different String elements and languages. Please any ideas is highly appreciated. Thank you
Check this Code for getting value from String.xml and compare :