Problem with Figure 9.12


Dear all,

When I run the app, everything works fine, apart from the fact that on the list, the Crimes are not immediately below each other, but there is a blank space between them. What seems to be the problem?
Here’s the code for CrimeListFragment:

public class CrimeListFragment extends Fragment {
    private RecyclerView mCrimeRecyclerView;
    private CrimeAdapter mAdapter;
    private Crime mCrime;

    private class CrimeHolder extends RecyclerView.ViewHolder {
        private TextView mTitleTextView;
        private TextView mDateTextView;
        private CheckBox mSolvedCheckBox;

        public void bindCrime(Crime crime) {
            mCrime = crime;

        public CrimeHolder(View itemView) {
            mTitleTextView = (TextView) itemView.findViewById(;
            mDateTextView = (TextView) itemView.findViewById(;
            mSolvedCheckBox = (CheckBox) itemView.findViewById(;

    private class CrimeAdapter extends RecyclerView.Adapter<CrimeHolder> {
        private List<Crime> mCrimes;

        public CrimeAdapter(List<Crime> crimes) {
            mCrimes = crimes;

        public CrimeHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            LayoutInflater layoutInflater = LayoutInflater.from(getActivity());
            View view = layoutInflater.inflate(R.layout.list_item_crime, parent, false);
            return new CrimeHolder(view);

        public void onBindViewHolder(CrimeHolder holder, int position) {
            Crime crime = mCrimes.get(position);


        public int getItemCount() {
            return mCrimes.size();


    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment__crime_list, container, false);
        mCrimeRecyclerView = (RecyclerView) view.findViewById(;
        mCrimeRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        return view;

    private void updateUI() {
        CrimeLab crimeLab = CrimeLab.get(getActivity());
        List<Crime> crimes = crimeLab.getCrimes();

        mAdapter = new CrimeAdapter(crimes);

You can delete this thread. Thanks to another user I’ve found what the problem was. RelativeLayout’s height should be set to wrap_content, and it works fine.


Good solution. Thank you. Had the same problem. I thought that there was a problem with model, I mean data generation ( list of crimes), but the stumbling block was the view -> relative layout. Thank you


Thank you very much. think carefully.match_parent is occupy the entire screen.