0

大家可以帮我在这个活动中集成 Startapp 网络吗,这是我的代码,它没有我尝试集成它的 oncreate 方法,但我失败了。请帮我。你可以在下面找到代码,它不包含 oncreate 方法。我是编码新手,我尝试了很多时间来解决这个问题,如果有 oncreate 方法对我来说很容易,我可以轻松集成广告网络。请大家处理任何想法都会帮助我。谢谢

public class MainFragment extends Fragment {

    public MainFragment() {
        // Required empty public constructor
    }

    private final String TAG = "MainFragment";
    Activity activity;
    AdView bannerAdView;
    boolean isAdLoaded;
    CardView cardVideoToGIF, cardImagesToGIF, cardCaptureImage, cardVideoToAudio, cardVideoCutter, cardGallery;
    LinearLayout linearRow2;

    private String SELECTED_TYPE = Constants.TYPE_GIF;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_main, container, false);
    }

    @Override
    public void onResume() {
        super.onResume();
        if (bannerAdView != null) {
            bannerAdView.resume();
        }
        ((MainActivity) activity).setTitle("");
        ((MainActivity) activity).setDrawerState(true);

        if (!MyApplication.isFFmpegSupports) {
            linearRow2.setVisibility(View.GONE);
        }
    }

    @Override
    public void onPause() {
        if (bannerAdView != null) {
            bannerAdView.pause();
        }
        super.onPause();
    }

    @Override
    public void onDestroy() {
        if (bannerAdView != null) {
            bannerAdView.destroy();
        }
        super.onDestroy();
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        initViews(view);

        cardVideoToGIF.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showPopupMenu(cardVideoToGIF);
                SELECTED_TYPE = Constants.TYPE_GIF;
            }
        });
4

1 回答 1

0

用以下代码替换您的代码

public class MainFragment extends Fragment {

 // Add these lines of code which is the onCreate method of your Fragment
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);

         // put your integration code here
        Log.i("MainFragment", "onCreate()");
     }

public MainFragment() {
    // Required empty public constructor
}

private final String TAG = "MainFragment";
Activity activity;
AdView bannerAdView;
boolean isAdLoaded;
CardView cardVideoToGIF, cardImagesToGIF, cardCaptureImage, cardVideoToAudio, cardVideoCutter, cardGallery;
LinearLayout linearRow2;

private String SELECTED_TYPE = Constants.TYPE_GIF;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    return inflater.inflate(R.layout.fragment_main, container, false);
}

@Override
public void onResume() {
    super.onResume();
    if (bannerAdView != null) {
        bannerAdView.resume();
    }
    ((MainActivity) activity).setTitle("");
    ((MainActivity) activity).setDrawerState(true);

    if (!MyApplication.isFFmpegSupports) {
        linearRow2.setVisibility(View.GONE);
    }
}

@Override
public void onPause() {
    if (bannerAdView != null) {
        bannerAdView.pause();
    }
    super.onPause();
}

@Override
public void onDestroy() {
    if (bannerAdView != null) {
        bannerAdView.destroy();
    }
    super.onDestroy();
}

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    initViews(view);

    cardVideoToGIF.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showPopupMenu(cardVideoToGIF);
            SELECTED_TYPE = Constants.TYPE_GIF;
        }
    });
于 2018-07-11T10:04:10.123 回答