I have the following code for a RecyclerView:
public class HomeFragment extends Fragment {
public static HomeFragment newInstance() {
return new HomeFragment();
}
private RecyclerView mRecyclerView;
private PostAdapter mAdapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_home, container, false);
mRecyclerView = view.findViewById(R.id.home_recycler_view);
mRecyclerView.setHasFixedSize(true);
List<Post> postList = new ArrayList<>();
try {
postList.add(new Post(1, new JSONObject("{}"), new ArrayList<Bitmap>()));
} catch (JSONException e) {
e.printStackTrace();
}
mAdapter = new PostAdapter(postList);
mAdapter.notifyDataSetChanged();
mRecyclerView.setAdapter(mAdapter);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
mRecyclerView.setLayoutManager(linearLayoutManager);
return inflater.inflate(R.layout.fragment_home, container, false);
}
}
This produces the error:
E/RecyclerView: No adapter attached; skipping layout
even though there is clearly an adapter attached to the RecyclerView. What am I doing wrong?