0

my code is this

 ll.setBackground(Drawable.createFromPath(new ImageLoader().fullPath+"/desiredFilename.png"));

ll is the object of my linear layout ,is this the correct method

   Bitmap bitmap = BitmapFactory.decodeFile(new ImageLoader().fullPath+"/desiredFilename.png");
              Resources res=getResources();
              BitmapDrawable bitmapDrawable = new BitmapDrawable(res,bitmap);
              ll.setBackground(bitmapDrawable);

i also used this code but dosent work shows error noSuchMethods

Ameen Maheen
  • 2,719
  • 1
  • 28
  • 28
  • [http://stackoverflow.com/questions/12781501/android-setting-linearlayout-background-programmatically](http://stackoverflow.com/questions/12781501/android-setting-linearlayout-background-programmatically) – M D Dec 08 '14 at 07:00

1 Answers1

2

try this way

  ll.setBackgroundDrawable(bitmapDrawable);

instead of

  ll.setBackground(bitmapDrawable);
M D
  • 47,665
  • 9
  • 93
  • 114
  • thanks for the help,i have tried it before and its works perfectly then why am i asking this question means ll.setBackgroundDrawable(bitmapDrawable); seem to be deprecated so im looking for a new solution – Ameen Maheen Dec 08 '14 at 06:58
  • @AmeenMaheen Check this [http://stackoverflow.com/questions/12523005/android-set-background-drawable-programmatically](http://stackoverflow.com/questions/12523005/android-set-background-drawable-programmatically) – M D Dec 08 '14 at 06:59
  • :-) what will i do if i have to load the image from the sd card like the code in my question.? – Ameen Maheen Dec 08 '14 at 07:03