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 8624021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:25:22+00:00 2026-06-12T07:25:22+00:00

Suppose I have a resource xml file like this: <?xml version=1.0 encoding=UTF-8?> <resources> <array

  • 0

Suppose I have a resource xml file like this:

<?xml version="1.0" encoding="UTF-8"?>
<resources>
    <array name="difficulties">
        <item>
            <integer name="level">1</integer>
            <integer name="fixed_blocks">2</integer>
            <integer name="color_count">2</integer>
        </item>
        <item>
            <integer name="level">2</integer>
            <integer name="fixed_blocks">4</integer>
            <integer name="color_count">3</integer>
        </item>
        <item>
            <integer name="level">3</integer>
            <integer name="fixed_blocks">6</integer>
            <integer name="color_count">3</integer>
        </item>
    </array>    
</resources>

How can I get the integer values from an item by name? The TypedValue‘s API doesn’t seem to contain any methods for this. If this is not possible with the TypedArray how IS it?

If I can get a value from an item by its ordinal it will be OK too.

  • 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-12T07:25:23+00:00Added an answer on June 12, 2026 at 7:25 am

    I don’t recall this being possible(but I could be wrong). Judging by the structure of an item(in the difficulties array) you could do something else, you could use an array of integer arrays. Knowing that the item array has level at the first position, fixed_blocks as the second position etc you could easily get the values. An example of this you can find here Android Resource – Array of Arrays

    Edit:
    Is this the method you’re looking for?

    private int[] getLevelConstants(int level) {
        int[] result = null;
        TypedArray ta = getResources().obtainTypedArray(R.array.difficulties);
        // keep in mind the differences between the level(starts at 1) and the index of the difficulties array which starts at 0
        int id = ta.getResourceId(level, 0); 
        if (id > 0) {
            result = getResources().getIntArray(id);
        } else {
            // something bad
        }
        return result;
    }
    

    and the array will be:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
    
        <integer-array name="difficulties">
            <item>@array/level1</item>
            <item>@array/level2</item>
        </integer-array>
    
        <integer-array name="level1" >
            <item>1</item>
            <item>2</item>
            <item>2</item>
        </integer-array>
    
        <integer-array name="level2" >
            <item>2</item>
            <item>4</item>
            <item>3</item>
        </integer-array>
    
    </resources>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom style file( style.xml ) in res/values that looks like this:
Suppose I have a resource located in ~/Resources/R1.png This resource's relative URL will vary
suppose i have a jax-rs resource class that looks like this: @Path(/nodes) public class
Suppose we have the name written in any none-latin letters - languages, like Arabic,
Suppose I have a css style like this: .foo a, .foo a:visited .foo a:hover
Suppose I have a class like this: #include <iostream> using namespace std; class Boda
Suppose we have some resource(a file on disk) in which we have to write
Suppose I have a context menu as a window resource: <Window.Resources> <ContextMenu x:Shared=false x:Key=ContextMenu>
Let´s say I´ve got the following xml string: <Item Name=\$Resources:myresource,somestring;\</Item> Now I want to
in my application i have this code: <Grid Name=BaseGrid> <Grid.Resources> <XmlDataProvider x:Name=ScenesXmlName x:Key=ScenesXml XPath=person

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.