I am trying to implement a RecycleView adapter that has CardViews as each row. 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.
As seen in this picture I get nothing in the recycle view but I am expecting "Test Title" and "Test Message" in a 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.
// use a linear layout manager
recycle.setLayoutManager(new LinearLayoutManager(getActivity());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.