Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6747739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:28:48+00:00 2026-05-26T12:28:48+00:00

Good day, i will try to explain my problem as best as i can.

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:28:49+00:00Added an answer on May 26, 2026 at 12:28 pm

    Check this Code for getting value from String.xml and compare :

        String[] categoriesAndDescriptions =getResources().getStringArray(R.array.myPlacesArray);
        for(String cad : categoriesAndDescriptions) {
            String categoryAndDesc = cad;
            Log.v("CategoryName", categoryAndDesc);
            if(place.equalsIgnoreCase(categoryAndDesc)){
            //Do your Stuffs here
            }
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good day, Stackoverflow! I have a little (big) problem with porting one of my
Good day, i will try and explain myself here. i am trying to create
Good Day all, I have an existing site built. I was wondering, how can
Good day! I have met problem with synchronizing threads. I am writing program which
Good day to all, Can some one guide me in displaying a simple post
Good day, I'm having a problem with asp.net 2.0 viewstate. Basically, I want to
Good day. I have little usage of Flash CS4, however i have to build
Good Day! i have installed xcode latest in my snow leopard, now i have
Good day all; I have an UIImageView that I animate around a large UIView.
Good day all, I have written an application that i require to have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.