gpt4 book ai didi

java - Cardview 内部片段

转载 作者:行者123 更新时间:2023-12-02 04:05:35 26 4
gpt4 key购买 nike

我试图将卡片放入其中一个片段中,但出现此错误:没有适用于“(com.sample.app.FragmentOne)”的构造函数。顺便说一下,我使用的是 AIDE IDE。

错误是这里的(this):

mLayoutManager = new LinearLayoutManager(this);

FragmentOne.java

package com.sample.app;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Menu;
import android.view.MenuItem;

import com.sample.app.MainActivity;
import com.sample.app.R;

public class FragmentOne extends Fragment {

RecyclerView mRecyclerView;
RecyclerView.LayoutManager mLayoutManager;
RecyclerView.Adapter mAdapter;


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

// Inflate the layout for this fragment
final View view = inflater.inflate(R.layout.fragment_one, container, false);

((MainActivity) getActivity()).getSupportActionBar().setTitle("Fragment One");

mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
mRecyclerView.setHasFixedSize(true);

mLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(mLayoutManager);

mAdapter = new CardAdapter();
mRecyclerView.setAdapter(mAdapter);

return view;
}

}

请帮助我,提前致谢。

最佳答案

我改变了这个

mLayoutManager = new LinearLayoutManager(this); 

进入

mLayoutManager = new LinearLayoutManager(getActivity());

关于java - Cardview 内部片段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34311480/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com