[英]Cannot resolve method onCreate() in sub class
In a sub class of PopupWindow the onCreate methods don't seem available from the super class. 在PopupWindow的子类中,超类似乎无法使用onCreate方法。 Get the error "cannot resolve method onCreate()".
得到错误“无法解析方法onCreate()”。
All the other methods are available. 所有其他方法均可用。
Thanks. 谢谢。
import android.widget.PopupWindow;
public class MyPopupWindow extends PopupWindow
{
public void MyPopupWindow()
{
super.onCreate();
}
}
The "super" keyword is used to invoke an overridden superclass's method. “ super”关键字用于调用重写的超类的方法。 In this case MyPopupWindow() is not a method of the superclass PopupWindow and isn't overriding a method.
在这种情况下,MyPopupWindow()不是超类PopupWindow的方法,并且不会覆盖方法。
See "Using the Keyword super". 请参阅“使用超级关键字”。
PopupWindow also doesn't have the method onCreate(), because it isn't an Activity or Fragment. PopupWindow也没有onCreate()方法,因为它不是Activity或Fragment。
See Android PopupWindow reference. 请参阅Android PopupWindow参考。
Many thanks for the replies. 非常感谢您的答复。 Was doing so pretty basic mistakes.
在做这么漂亮的基本错误。 Have managed to create the class properly now and is doing as intended.
现在已经设法正确地创建了类并且正在按预期进行。 Highlights the view that was tapped and unhighlights it once the popup is dismissed.
突出显示已点击的视图,并在取消弹出窗口后取消突出显示该视图。
public class MyPopupWindow extends PopupWindow
{
private View tv;
private int bc;
MyPopupWindow(View vvv,int width,int height,View tappedView,int backColor)
{
super(vvv,width,height);
tappedView.setBackgroundColor(0xFFffb6c1);
tv = tappedView;
bc = backColor;
}
@Override
public void dismiss()
{
if (tv != null)
tv.setBackgroundColor(bc);
super.dismiss();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.