1

I need to change the background of a view programmatically so I was following this. It says to make sure that you mark it with annotations. Where do I do that? I've tried the top of the class, the top of the method, inside the method. I'm confused. It's a little bothersome that I even need annotations to do this very simple/common thing anyway.

if (android.os.Build.VERSION.SDK_INT >= 
    android.os.Build.VERSION_CODES.JELLY_BEAN) {
    rowView.setBackground(R.drawable.blue_background);
}
else {
    rowView.setBackgroundDrawable(R.drawable.blue_background);
}

The setBackground method gives me an error saying it is only available for APIs level 16 and above while my app supports lower than that.

The setBackgroundDrawable method is deprecated as of API level 16.

I'm being told to use @TargetApi(16) and @SuppressWarnings("deprecation") but where? I'm using Eclipse for my IDE on Windows 7.

Community
  • 1
  • 1
rkeller
  • 69
  • 10

1 Answers1

0

If you double-click on the error, Eclipse will create an auto-fix and the problem should disappear.

Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223