繁体   English   中英

RecycleView适配器未添加到视图

[英]RecycleView adapter not adding to the view

我正在尝试实现具有CardViews作为每一行的RecycleView适配器。 即使我已创建适配器并将其附加到活动视图,也不会显示名片视图。

我正在使用Tabbed活动,并尝试修改OnCreateView()方法。

img

如图所示,在回收视图中我什么也没得到,但是我希望CardView中有“测试标题”和“测试消息”。

public static class PlaceholderFragment extends Fragment {
    /**
     * The fragment argument representing the section number for this
     * fragment.
     */
    private static final String ARG_TAB_NUMBER = "tab_number";

    public PlaceholderFragment() {
    }

    /**
     * Returns a new instance of this fragment for the given section
     * number.
     */
    public static PlaceholderFragment newInstance(int tabNumber) {
        PlaceholderFragment fragment = new PlaceholderFragment();
        Bundle args = new Bundle();
        args.putInt(ARG_TAB_NUMBER, tabNumber);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_coversations, container, false);
        RecyclerView recycle = (RecyclerView) rootView.findViewById(R.id.recycleView);
        List<RecyclerData> list = new ArrayList<>();
        RecycleViewAdapter adapter = new RecycleViewAdapter(list);
        recycle.setAdapter(adapter);
        RecyclerData r = new RecyclerData("Test Title", "Test Message", 0);
        list.add(r);
        adapter.notifyDataSetChanged();
        return rootView;
    }
}

您需要为回收者视图设置一个布局管理器。 在您的情况下,请尝试将LinearLayoutManager添加到回收器视图。

// use a linear layout manager
recycle.setLayoutManager(new LinearLayoutManager(getActivity());

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM