为什么我不能覆盖Fragment.onAttach(Context context)?

时间:2019-04-25 22:31:57

标签: java android android-fragments

我们团队中的一位成员在Android Studio中生成了存根片段,并且onAttach(Context context)是自动生成的。但是,编译器在我的代码中报告了以下错误,如下所示:

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class TestFragment extends Fragment {
    ...
    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
    }
}
  1. error: method does not override or implement a method from a supertype

  2. error: incompatible types: Context cannot be converted to Activity

为什么在编译时会收到这些错误消息?

0 个答案:

没有答案
相关问题