Sheehan Alam
Sheehan Alam

Reputation: 60879

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.

Upvotes: 13

Views: 34714

Answers (4)

Rachit Vohera
Rachit Vohera

Reputation: 745

just put your .png file in mipmap folder

Upvotes: 1

Dante
Dante

Reputation: 99

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

Upvotes: 1

skorulis
skorulis

Reputation: 4381

Use:

chartImageView.setImageResource(R.drawable.nochart);

Upvotes: 24

Jared
Jared

Reputation: 1760

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

android:src="@drawable/nochart"

Upvotes: 3

Related Questions