I am getting this error:
Call requires API level 14 (current min is 8): android.view.ViewGroup#canScrollHorizontally.
How I can resolve this in API level before 14?
public class ViewPagerEx extends ViewGroup{
@Override
public boolean performAccessibilityAction(View host, int action, Bundle args) {
if (super.performAccessibilityAction(host, action, args)) {
return true;
}
switch (action) {
case AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD: {
if (canScrollHorizontally(1)) {
setCurrentItem(mCurItem + 1);
return true;
}
} return false;
case AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD: {
if (canScrollHorizontally(-1)) {
setCurrentItem(mCurItem - 1);
return true;
}
} return false;
}
return false;
}
public boolean canScrollHorizontally(int direction) {
if (mAdapter == null) {
return false;
}
final int width = getClientWidth();
final int scrollX = getScrollX();
if (direction < 0) {
return (scrollX > (int) (width * mFirstOffset));
} else if (direction > 0) {
return (scrollX < (int) (width * mLastOffset));
} else {
return false;
}
}
}
go to AndroidManifest.xml
you will find such code:
`<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />`
android:minSdkVersion
is what your looking for, i means that your app will work on devises having the same API level.
android:targetSdkVersion
is the API level that your app is designed to work on.
android:maxSdkVersion
is the maximum API level your app can work on.
implies your app can work on devices between android:minSdkVersion
and android:maxSdkVersion
so what you have to do is is changing you API level from 8 to 14 to support android.view.ViewGroup#canScrollHorizontally.
since it was added in level 14 .
take into consideration that lowering android:minSdkVersion
will support more android devices but you wouldn't be able to use methods introduced in higher API levels .
for more info check this detailed description
extra info :
0.7% ??? you might think twice before setting android:minSdkVersion="8"
From @KenWolf's suggestion: Using the support-v4
library, you can use ViewCompat
to check this:
// From within the View itself, just invoke the ViewCompat
// implementation with 'this' as the View parameter.
if (ViewCompat.canScrollHorizontally(this, 1)) {
// ...
}
Give this a try: Try changing your local method name to something else, and call it. For example change it to canScrollHorizontallyLocal() and so where you are calling it. ViewGroup has a method named like that, and it might be trying the super method instead of yours.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.