引用Appcompat活动中片段中的Recyclerview?

时间:2016-01-21 05:40:25

标签: java android visual-studio user-interface intellij-idea

嘿所以我有一个recyclerview和recyclerview适配器,如下所示。但是,这个rec​​yclerview适配器在扩展片段的活动中被夸大了。这次我想在扩展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;

1 个答案:

答案 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);