How to set a PNG file to an ImageView?

I have a file called nochart.png in /drawable.

How can I set this to an ImageView?

chartImageView.setImageDrawable(R.drawable.nochart);

Does not compile.

Answers


Use:

chartImageView.setImageResource(R.drawable.nochart);

you can also set the image using an xml file with the following attriblute

android:src="@drawable/nochart"

I encountered the same problem. The solution for me was to move the ".png" from "drawable-21" to "drawable".


Need Your Help

How do I avoid reflection injection attacks in PHP?

php reflection code-injection

I'm writing a class that allows you to bridge HTTP requests with class instances using JSON for data, without any implementation in the class you're bridging to. Basically this is how it works:

Apache Hadoop- Task process exit with nonzero status of 1

apache hadoop

I am new to apache hadoop, I have configured hadoop on my windows xp using cygwin by following the tutorial http://v-lad.org/Tutorials/Hadoop. Configuration was suucessfull, but while running a sa...