0

I want to set the background of my Gallery by an image (say background.jpg ) in Drawable folder.

As the prototype of the setBackground() method is

 void   setBackground(Drawable background)
Set the background to a given Drawable, or remove the background.

But I don't know how to refer to my image in this method. I have tried to refer like this

Gallery galleryModified;
galleryModified.setBackground(background);

But getting error in second line, saying unable to find resource.

Please reply if you know.

Thanks.

Vishal
  • 673
  • 3
  • 12
  • 24

2 Answers2

1

It seems, you are setting background from a resource from drawable folder, which have id, R.drawable.background, if it is the case, try following:

galleryModified.setBackgroundResource(R.drawable.background);
jeet
  • 29,001
  • 6
  • 52
  • 53
0

All resources in your project is parsed under R class automatically. You should always retrive them as an object, such as: R.drawable.drawable_name This is a basic way to retrieve many resource types. Just replace drawable keyword such as: R.string.name_of_string_resource R.id.id_control

Nguyen Minh Binh
  • 23,891
  • 30
  • 115
  • 165