Note that there are some explanatory texts on larger screens.

plurals
  1. POPNG file won't display in ImageView if source is set programatically
    primarykey
    data
    text
    <p>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 </p> <pre><code>src="@drawable.norusdpyr" </code></pre> <p>in the Activity's XML file, the file displays fine. BUT, if I put</p> <pre><code>String imageresource = "R.drawable." + parsedData[4].toString(); chart.setImageURI(Uri.parse(imageresource)); </code></pre> <p>where parsedData[4].toString() = "nor_usdpyr" I don't see anything. I've also tried</p> <pre><code>String imageresource = "android.resource://" + getPackageName() + "/R.drawable." + parsedData[4].toString(); chart.setImageURI(Uri.parse(imageresource)); </code></pre> <p>and</p> <pre><code>InputStream is = getClass().getResourceAsStream("/drawable/" + parsedData[4].toString()); chart.setImageDrawable(Drawable.createFromStream(is, "")); </code></pre> <p>and</p> <pre><code>String imageresource = "R.drawable." + parsedData[4].toString(); File file = new File(imageresource); chart.setImageDrawable(Drawable.createFromPath(file.getAbsolutePath())); </code></pre> <p>and</p> <pre><code>Context context = getApplicationContext(); int ResID = context.getResources().getIdentifier(imageresource, "drawable", "com.KnitCard.project"); chart.setImageResource(ResID); </code></pre> <p>finally,</p> <pre><code>chart.setImageURI(Uri.parse("android.resource://" + getPackageName() + "/R.drawable.nor_usdpyr")); </code></pre> <p>doesn't work.</p> <p>None of these work. What am I doing wrong? Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload