Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid - How to show images from resources drawable?
    text
    copied!<p>I'm not able to show an image which is saved in res/drawable folder. I use ImageGetter to do this. The code is below:</p> <pre><code>ImageGetter imageGetter3 = new ImageGetter() { public Drawable getDrawable(String source) { int id=0; if (source.equals("smiley")) { id = R.drawable.smiley; } Drawable d = getResources().getDrawable(id); d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); return d; } }; directions += "Je bent bij lokaal " + vertrek.getNaam() + "\n" + "Sta met je rug voor de deur\n" + Html.fromHtml("&lt;img src=\"smiley\"&gt;", imageGetter3, null) + " Draai naar links\n"; </code></pre> <p>What I see on the screen when running is a little square with "obj" text on it. So what is wrong? The image cannot be read or something else? How to show images?</p> <p>Honestly I have Googled a lot and tried other methods of ImageGetter as well, but none of them seems to work, I tried these too, they don't work:</p> <pre><code>ImageGetter imageGetter2 = new ImageGetter() { public Drawable getDrawable(String source) { Drawable d = null; d = Drawable.createFromPath(source); d.setBounds(0,0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); return d; } }; ImageGetter imageGetter = new ImageGetter() { public Drawable getDrawable(String source) { Drawable drawFromPath; int path = Route.this.getResources().getIdentifier(source, "drawable","com.prj56.tracingapp"); drawFromPath = (Drawable) Route.this.getResources().getDrawable(path); drawFromPath.setBounds(0, 0, drawFromPath.getIntrinsicWidth(), drawFromPath.getIntrinsicHeight()); return drawFromPath; } }; </code></pre> <p>========================================================= if (....) { ImageView iv1 = new ImageView(this); iv1.setImageResource(R.drawable.smiley);</p> <pre><code> directions += "Je bent bij lokaal " + vertrek.getNaam() + "\n" + "Sta met je rug voor de deur\n"; HERE COMES THE IMAGE! BUT HOW TO DO THIS? It's within directions textview... directions += " Draai naar links\n"; } </code></pre>
 

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