New to Android development and have decided to use NetBeans 6.9.1 as my IDE. So far the process has been somewhat painful, but I’m getting things rolling. However, I am creating an ImageView subclass for my first custom View and I can’t figure out how to add my Box.png file to the project. Drag and Drop doesn’t work, there are no right-click options to add a file to the Resources folder, no dropdown menus to add images, no way to add the image to a package. Could use some insight, thanks!
Share
Just go to the project folder and copy the images you want into the
res/drawablefolder. The IDE helps you a lot with code completion, error checking, etc… but that simple task can be done by hand.Then, you can reference your resources by using something like:
R.drawable.imageNotice that I’m not using the image extension. If you wonder whatRis, let me give you a brief explanation:Each resource that is saved in the resources directory is referenced in the
Rclass. That’s a file that is autogenerated by Android and it’s used to reference those resources from your code. In this case, it will be inR.drawable.*since it’s a drawable resource. There are other kind of resources, like layouts:R.layout.somethingor stringsR.string.whatever. That’s essential for the android development, so you better read some tutorials (or buy books) in order for you to get started.So, in your case will be something like
setImageDrawable(R.layout.wood);However, I highly recommend to read first a couple of tutorials. Google about it, you will find tons of them.