Question

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.

Was it helpful?

Solution

Use:

chartImageView.setImageResource(R.drawable.nochart);

OTHER TIPS

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".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top