如何覆盖一个函数?

时间:2014-07-17 10:00:29

标签: android cordova override cordova-3 cordova-2.0.0

请告诉我如何正确覆盖“createViews”?如果我把@Override放在它之前,它会说:“WhatSnap类型的方法createViews()必须覆盖或实现超类型方法” 如果我删除@Override它就不会被执行。 这是第一堂课:https://github.com/apache/cordova-android/blob/master/framework/src/org/apache/cordova/CordovaActivity.java#L267

这是我想要覆盖createViews的第二个:

package com.Snap.What;

import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.Display;
import android.view.View;
import android.widget.RelativeLayout;

import org.apache.cordova.*;

import com.startapp.android.publish.StartAppAd;
import com.startapp.android.publish.StartAppSDK;
import com.startapp.android.publish.banner.Banner;

public class WhatSnap extends CordovaActivity 
{
    private CordovaWebView cordova_webview;
    private StartAppAd startAppAd = new StartAppAd(this);

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        super.init();
        // Set by <content src="index.html" /> in config.xml
        super.loadUrl(Config.getStartUrl());
        //super.loadUrl("file:///android_asset/www/index.html");
        StartAppSDK.init(this, "xxx", "xxx", true);
        Log.e("activity", "activity");
    }

    @Override 
    protected void createViews(){
        RelativeLayout layout = new RelativeLayout(this);

        RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
             RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.MATCH_PARENT);
        layout.setLayoutParams(lp);

        appView.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT));
        Log.e("createViews", "createViews");
                appView.setVisibility(View.INVISIBLE);
            layout.addView((View) appView);
            setContentView(layout);

            Banner startAppBanner = new Banner(this);
            RelativeLayout.LayoutParams bannerParameters =
                        new RelativeLayout.LayoutParams(
                                    RelativeLayout.LayoutParams.WRAP_CONTENT,
                                    RelativeLayout.LayoutParams.WRAP_CONTENT);
            bannerParameters.addRule(RelativeLayout.CENTER_HORIZONTAL);
            bannerParameters.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);    
          // Add to main Layout
            layout.addView(startAppBanner, bannerParameters);
    }


    @Override 
    protected CordovaWebView makeWebView (){ 
         Log.e("CordovaWebView", "CordovaWebView");
        return new CordovaWebView(WhatSnap.this);
    }




}

1 个答案:

答案 0 :(得分:1)

您必须使用与超类方法相同的Access Modifier。将覆盖签名更改为,

@Override 
protected void createViews(){
    //Your code here
}