Simply trying to extend View and do some custom work, but Eclipse will complain when I attempt to override the setFrame method. Claiming there isn’t a method in the parent class to override:
The method setFrame(int, int, int, int) of type Test must override or implement a supertype method
Here is the signature of the method from android SDK source.
protected boolean setFrame(int left, int top, int right, int bottom)
As you can see it’s not private or package level, or even specified as final… just protected. Which should mean I am totally able to override it in a subclass. Right? Below is the bare minimum of what I’m trying to do in Eclipse. Perhaps it is just an Eclipse error, but I’m not too familiar with using Ant to check against that.
Edit: To those answering that setFrame is not defined in the View class, I can assure you it is. How else do you think I got the method signature? It is even called during layout(). Or am I seriously just crazy?
git HEAD: View.java
Cupcake (1.5r4): View.java
You can even see the method being overriden in the ImageView and TextView classes…this is why I am seriously confused as to why I cannot override it myself from View directly…
public class Test extends View {
public Test(Context context) {
super(context);
}
public Test(Context context, AttributeSet attrs) {
super(context, attrs);
}
public Test(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected boolean setFrame(int left, int top, int right, int bottom) {
return super.setFrame(left, top, right, bottom);
}
}
According to the documentation,
setFrameis not defined in theViewclass (not strictly true – see edit). Surprising, each subclass,TextViewandImageView, define it themselves. You’ll have to have to extend the specific subclass for each widget you want to override this behavior. This is based on the docs forAndroid 2.3 r1 - 05 Jan 2011 12:43.See the documentation:
Classes that define setFrame
http://www.google.com/search?q=site:developer.android.com+%22boolean+setFrame%22
TextView and ImageView.
Edit:
As the OP points out in the comments, the method is clearly defined in the
View.javasource code. However, the documentation acts as if the method isn’t defined there.The reason for this is that the setFrame() method in
Viewhas the @hide Javadoc tag:Apparently, this hides the method from the Javadoc:
http://www.androidjavadoc.com/?p=63
Is it possible that the reason it can’t be overridden is that the Eclipse plug-in for Android or the Android compiler is somehow enforcing the
@hidetag? I don’t know.