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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:09:50+00:00 2026-06-06T09:09:50+00:00

I had this, which was working fine: public static Integer[] photos = new Integer[]

  • 0

I had this, which was working fine:

public static Integer[] photos = new Integer[]    
{R.drawable.photo1,R.drawable.photo2,R.drawable.photo3};

this.setImageResource(photos[mCellNumber]);

But I decided I wanted to put the filenames in an XML file instead, which I did, like this:

<?xml version="1.0" encoding="UTF-8"?>
<resources>
<array name="Red">
    <item>R.drawable.photo1</item>
    <item>R.drawable.photo2</item>
    <item>R.drawable.photo3</item>
</array>
</resources>

And tried stuff like this:

String[] month = getResources().getStringArray(R.array.Red);
this.setImageResource(month[mCellNumber]);

..and..

String[] month = getResources().getStringArray(R.array.Red);
int bla = Integer.parseInt(month[mCellNumber]);
this.setImageResource(bla);

I understand why it’s not working (strings/ints), but I haven’t found any simple way of handling the string to integer conversion part or alternatively, using setImageResource with a string as parameter. Any suggestions?

  • 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-06T09:09:51+00:00Added an answer on June 6, 2026 at 9:09 am
    String[] month = getResources().getStringArray(R.array.Red);
    int bla = Integer.parseInt(month[mCellNumber]);
    

    looks it will throw exception R.drawable.photo1 as a string is not a valid number.

    You an try with only saving name like photo1,photo2,photo3 and then do as below:

    …

    Android – Store drawable ids in a custom XML file

    you can try with only saving the name like “joe_pic” and can get this way

    ..

       String uri = "drawable/icon";
    
        // int imageResource = R.drawable.icon;
        int imageResource = getResources().getIdentifier(uri, null, getPackageName());
    
        ImageView imageView = (ImageView) findViewById(R.id.myImageView);
        Drawable image = getResources().getDrawable(imageResource);
        imageView.setImageDrawable(image);
    }
    

    but if you have already added “R.drawable.joe_pic” complete can use String.split to get 3 rd string part

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had few pages with normal table border which were working fine until I
I had this working fine yesterday, made some changes and I have no idea
I was looking at an authentication system which had this code: # prevents a
I always had this question: When i dont mind the exact floating number Which
I had accidentally tried this, which compiles! So I was wondering what could this
Had this working; at one stage. The problem is the following text is now
I had this error when I browse new web site that site sub from
I have written a program which will serialize and de-serialize, it does this fine
I'm binding a ListView to a collection of objects which is working fine. Unfortunately
I had this Wordpress installation which was installed in a subfolder (not root). Like

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.