简体   繁体   English

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

[英]Reference a Recyclerview that was in a fragment in Appcompat activity?

Hey so I have a recyclerview and a recyclerview adapter as shown below. 嘿,所以我有一个recyclerview和一个recyclerview适配器,如下所示。 However, this recyclerview adapter was inflated inside an activity that extends fragment. 但是,此recyclerview适配器在扩展片段的活动中膨胀了。 This time I want to use it in an activity that extends AppCompatActivity, How do I do that? 这次,我想在扩展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;

just use the same code inside your onCreate() method of the Activity 只需在Activity的onCreate()方法内使用相同的代码

// Initialize recycler view
mRecyclerView = (RecyclerView) findViewById(R.id.ID);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mAdapterDashBoard=new AdapterDashBoard(this);
mRecyclerView.setAdapter(mAdapterDashBoard);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 appcompat 和片段在一个活动中 - appcompat and fragment in one activity 由于 recyclerView 导致 Activity/fragment 滞后 - Lag in Activity/fragment due to recyclerView RecyclerView中CardView上的onClickListener,由Activity中的片段中的片段创建 - onClickListener on a CardView in a RecyclerView created by a Fragment in a Fragment in an Activity 我无法从活动的片段中填充recyclerview - I cant fill the recyclerview in fragment from activity RecyclerView 在 Fragment 中不显示项目,但在 Activity 中有效 - RecyclerView does not show items in Fragment, but works in Activity 如何将参考从RecyclerView传递到另一个活动 - How to pass reference from RecyclerView to another activity Activity 和 Fragment 是否构造循环引用? - Does Activity and Fragment construct circular reference? 屏幕旋转后的片段活动参考 - Fragment activity reference after screen rotation 如何根据RecyclerView中的单击项在新活动中打开特定片段 - How to open specific Fragment in new Activity depending on clicked item in RecyclerView 共享元素从viewpager内的fragment recyclerview过渡到新活动? - Shared element transition from fragment recyclerview inside viewpager to new activity?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM