[英]RecycleView adapter not adding to the view
I am trying to implement a RecycleView adapter that has CardViews as each row. 我正在尝试实现具有CardViews作为每一行的RecycleView适配器。 The card views do not show up even though I have the adapter created and attached to the view of the activity.
即使我已创建适配器并将其附加到活动视图,也不会显示名片视图。
I am using the Tabbed activity and trying to modify the OnCreateView() method. 我正在使用Tabbed活动,并尝试修改OnCreateView()方法。
As seen in this picture I get nothing in the recycle view but I am expecting "Test Title" and "Test Message" in a CardView. 如图所示,在回收视图中我什么也没得到,但是我希望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;
}
}
You need to set a layout manager to your recycler view. 您需要为回收者视图设置一个布局管理器。 In your case try adding a LinearLayoutManager to your recycler view.
在您的情况下,请尝试将LinearLayoutManager添加到回收器视图。
// use a linear layout manager
recycle.setLayoutManager(new LinearLayoutManager(getActivity());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.