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

  • Home
  • SEARCH
  • 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 7801621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:00:31+00:00 2026-06-02T01:00:31+00:00

I am trying to work out if I can use a resource file, while

  • 0

I am trying to work out if I can use a resource file, while developing my android app, to hold a list of numbers using a string value as a key. For example

numbers(“UK”)= 999
numbers(“US”) = 911

As I said, this would ideally be in resource file rather than a Java class as it is more maintainable

  • 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-06-02T01:00:32+00:00Added an answer on June 2, 2026 at 1:00 am

    You want to define a dictionary in resources. There’s no way to do that directly. You could however define the keys and values as arrays, then build the dictionary.

    In res/values/arrays.xml, have something like,

    <string-array name="emergency_keys">
        <item>UK</item>
        <item>US</item>
                ....
    </string-array>
    <integer-array name="emergency_values">
        <item>999</item>
        <item>911</item>
                ...
    </integer-array>
    

    Then in your code you have this utility method,

    Map<String,Integer> getDict(int keyId, int valId) {
      String[] keys = getResources().getStringArray(keyId);
      int[] values = getResources().getIntArray(valid); 
    
      Map<String,Integer> dict = new HashMap<String,Integer>();
      for (int i = 0, l = keys.length; i < l; i++) {
        dict.put(keys[i], vals[i]);
      }
    
      return dict;
    }
    

    When you need the dictionary in your code, do this,

    Map<String,Integer> emergencyNumbers = getDict(R.array.emergency_keys, R.array.emergency_values);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a generic Collection and am trying to work out how I can
I'm trying to work out how to use the CrmService to close a Task
I am trying to work out if I can parallelise the training aspect of
I've been stuck on this for a while now and I can't work out
I'm trying to work out how this Mock (using the Moq framework) stuff all
I am trying work out with MERGE statment to Insert / Update Dimension Table
Im trying to work out how to get the value from one setting in
I trying to work out what regex will match filenames in quotes. Eg. blah
I'm trying to work out what a BizTalk call to a web service is
I'm trying to work out what the best method to passing a large number

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.