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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:20:00+00:00 2026-06-05T14:20:00+00:00

I have a png file in my res/drawable-ldpi folder. I’m working in Eclipse with

  • 0

I have a png file in my res/drawable-ldpi folder. I’m working in Eclipse with the emulator, but I’ve tried this on my 2.2.1 Android phone and I get the same behavior. I have an ImageView and I want to set the src programatically, based on a database call. If I just put

src="@drawable.norusdpyr"

in the Activity’s XML file, the file displays fine. BUT, if I put

String imageresource = "R.drawable." + parsedData[4].toString();
chart.setImageURI(Uri.parse(imageresource));

where parsedData[4].toString() = “nor_usdpyr” I don’t see anything. I’ve also tried

String imageresource = "android.resource://" + getPackageName() + "/R.drawable." + parsedData[4].toString();
chart.setImageURI(Uri.parse(imageresource));

and

InputStream is = getClass().getResourceAsStream("/drawable/" + parsedData[4].toString());
chart.setImageDrawable(Drawable.createFromStream(is, ""));

and

String imageresource = "R.drawable." + parsedData[4].toString();   
File file = new File(imageresource);
chart.setImageDrawable(Drawable.createFromPath(file.getAbsolutePath()));

and

Context context = getApplicationContext();
int ResID = context.getResources().getIdentifier(imageresource, "drawable", "com.KnitCard.project");
chart.setImageResource(ResID);

finally,

chart.setImageURI(Uri.parse("android.resource://" + getPackageName() + "/R.drawable.nor_usdpyr"));

doesn’t work.

None of these work. What am I doing wrong? Thanks!

  • 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-05T14:20:01+00:00Added an answer on June 5, 2026 at 2:20 pm

    First, this shouldn’t be working:

    src="@drawable.norusdpyr"
    

    The correct way is:

    android:src="@drawable/norusdpyr"
    

    Second, those string ids that you use in XML are only valid in XML. When the resources are built, all those strings are replaced by their respective integer values. Ideally, you won’t need to load a package resource from a string name. But if you do, you can look for the field with such name, get the integral value it holds, and call setImageResource. You were quite close with this version:

    int ResID = context.getResources().getIdentifier(imageresource, "drawable", "com.KnitCard.project");
    chart.setImageResource(ResID);
    

    except that imageResource should have been parsedData[4].toString() with no R.drawable. prefix. You can use context.getPackageName() instead of hardcoding your package name.

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

Sidebar

Related Questions

:) I have my drawable folder inside res but when I try to add
I have created bg3.9.png image following this tutorial http://developer.android.com/guide/developing/tools/draw9patch.html but when i put it
I have this main.xml file: <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=vertical android:layout_width=fill_parent android:layout_height=fill_parent android:background=@drawable/background
I have a PNG file in a UIImageView, and next to that I have
I have an image (PNG file) that has an alpha channel that is set
I have a image (png file) with opacity 35%, i want for example: Set
I have a directory containing a number of static file (*.png, *.css, etc). I
I have an .aspx file that outputs an image using the following methods: Server.MapPath(somefile.png)
I have several png image files with names like this - house_number_5.png house_number_512.png house_number_52352.png
I have an ImageView object that I'm setting the android:src=@drawable/some_xml_file instead of a standard

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.