嘿所以我有一个recyclerview和recyclerview适配器,如下所示。但是,这个recyclerview适配器在扩展片段的活动中被夸大了。这次我想在扩展AppCompatActivity的活动中使用它,我该怎么做?
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view=inflater.inflate(R.layout.fragment_dashboard,container,false);
mRecyclerView=(RecyclerView)view.findViewById(R.id.ID);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mAdapterDashBoard=new AdapterDashBoard(this);
mRecyclerView.setAdapter(mAdapterDashBoard);
return view;
答案 0 :(得分:0)
只需在Activity
的onCreate()方法中使用相同的代码// Initialize recycler view
mRecyclerView = (RecyclerView) findViewById(R.id.ID);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mAdapterDashBoard=new AdapterDashBoard(this);
mRecyclerView.setAdapter(mAdapterDashBoard);