简体   繁体   English

无法解析子类中的方法onCreate()

[英]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.

相关问题 在OnCreate中定义按钮-无法解析方法中的符号 - Defining Button in OnCreate - Cannot resolve symbol in method 无法解析onCreate或getMapAsync - Cannot resolve onCreate or getMapAsync Realm.init()无法解析方法init在Application onCreate中不起作用? - Realm.init() cannot resolve method init not working in Application onCreate? 圆形布局:无法解析onCreate(android.os.Bundle)方法 - Circular layout: Cannot resolve method onCreate(android.os.Bundle) 无法解析findViewById和onCreate方法 - Cannot resolve findViewById and onCreate methods 在Android中调用超类onCreate()方法时如何解决Activity中的NullPointerException - How to resolve NullPointerException in an Activity when calling super class onCreate() method in Android 无法解析 WifiManager 类中的公共方法 setFrequencyBand - Cannot resolve public method setFrequencyBand in WifiManager class 无法解析 FirebaseInstanceIDService 类中的方法“GetApplicationContext()” - Cannot resolve method "GetApplicationContext()" in FirebaseInstanceIDService class 无法解析片段类中的方法getsystemservice - cannot resolve method getsystemservice in Fragment Class 无法在扩展FragmentActivity的类中解析方法getActivity() - Cannot resolve method getActivity() in a class extending FragmentActivity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM