문제

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