繁体   English   中英

用其他包中的私有构造函数扩展类

[英]extend class with private constructor in other package

我想覆盖android中RecognizerIntent的视图。 为此,我尝试如下扩展Android中的RecognizerIntent类:

package com.example.myapp;

import android.content.Context; 
import android.speech.RecognizerIntent;

public class RecInt extends RecognizerIntent {

    public RecInt(Context c) {
        super(c);
//if I don't call super here, there is an error 'There is no default constructor available in RecognizerIntent'
    } 

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recint);
    }
}

但是我得到了错误

RecognizerIntent()在android.speech.RecognizerIntent中不是公开的,无法从外部包访问。

我还有什么办法可以扩展非公共类?

我想这样做,以便启动RecInt

Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
startActivityForResult(intent,100);

将显示setContentView(R.layout.activity_recint)中的视图,而不是RecognizerIntent视图。

RecognizerIntent()不是公开的

构造函数不是公共的。 全班公开

您可以扩展类,但不能调用super 目前尚不清楚您为什么这样做或提供上下文。 它似乎没有提供该构造函数

另外,该类不是Activity,因此所有onCreate代码都是错误的

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM