문제

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.

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top