Basically you can't do it. But, you can use it in upper version and provide some backwards compatibility in your code for older versions :
@TargetApi(Build.VERSION_CODES.FROYO)
private void allowSmoothScrollIfSupported() {
if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO ) {
list.smoothScrollToPosition(position)
} else {
list.scrollToPosition(position)
}
}
This method will only be executed on API versions 8 and above, and will not crash below : it will fallback on an old API (scrollToPosition
).
and in your AndroidManifest.xml
you can indicate that your target the newest api but support all of them from 5 and up :
<uses-sdk
android:minSdkVersion="5"
android:targetSdkVersion="17" />