0

I am attempting to make a custom implementation of Android's StackView by extending AdapterViewAnimator myself. There are several methods contained in AdapterViewAnimator which would prove useful to my subclass, and so I put my subclass in the same package android.widget hoping to gain access to them since they are package-level methods:

void configureViewAnimator(int numVisibleViews, int activeOffset) {
    if (activeOffset > numVisibleViews - 1) {
        // Throw an exception here.
    }
    mMaxNumActiveViews = numVisibleViews;
    mActiveOffset = activeOffset;
    mPreviousViews.clear();
    mViewsMap.clear();
    removeAllViewsInLayout();
    mCurrentWindowStart = 0;
    mCurrentWindowEnd = -1;
}

Note that this method is a package level method, which is why my subclass needs to be in android.widget as well. Even so, the compiler (Java 7) tells me that the method does not exist, and so I cannot call the method on my superclass in my class:

package android.widget;
public class Foo extends AdapterViewAnimator {
    public void init(){
        super.configureViewAnimator(3,1); // Method does not exist.
    }
}

Am I missing something here? Why can't my subclass call the superclass package-level method?

Matthew Runo
  • 1,387
  • 3
  • 20
  • 43

1 Answers1

1

You can refer to https://groups.google.com/forum/#!msg/android-developers/poC2Xyh-G4w/zKLBPNTryYMJ

"Android.jar now contains only the public APIs. If you compile against this jar, you are guaranteed your app will run against future versions of Android. As part of the process that removes private APIs from android.jar, the code is stubbed out, because it's never executed so there's no reason to make the SDK much bigger because of it."

This explain why the method configureViewAnimator is not found as you are compiling against the android.jar, which include only public API(configureViewAnimator is a package private method)

Brian Lai
  • 83
  • 1
  • 5