質問

Inside a method I run a line which is different for different SDKs. And the lint marker always marks it as an error and suggests me to add a new api annotation for the whole method, but this is only one line of code I think it's pointless to create a new method just for this.
I have this in many places, but for example :

private void methodA(){

  ... 
  some code (that is good for both) 
  ... 

  if(Build.VERSION>SDK_INT >= 16)
    pb.setBackground(anim);
  else
    pb.setBackgroundDrawable(anim);

  ...
  more code
  ...
}
役に立ちましたか?

解決

Window->Preferences->Android->Lint Error Checking:

Change NewApi Severity to Ignore.

enter image description here

他のヒント

In Eclipse, you have to use an annotation or disable the inspection completely.

If you used the new Android Studio, however, you wouldn't have this problem. It will understand that the code under the if block will run only if the API level is >= 16, and will check the methods accordingly.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top