ViewGroup parent - what does it actually refer to?


I’m in p.183 and confused about this particular line of code:

public CrimeHolder onCreateView (ViewGroup parent, int viewType) { … }

Does the parent here refer to a layout? If it does, which one, in particular, does it refer to?

Then later on, it gets used as a parameter on LayoutInflater.inflate:

layoutInflater.inflate(android.R.layout.simple_list_item1, parent, false);

What does this line of code tell us, if attachToRoot is set to True?


The parent is the ViewGroup that your view will go into. So, in your first example, you are creating a new row in your RecyclerView. The parent for the row is the RecyclerView.

The parent is important in both of those places because of LayoutParams. We wrote a blog post on this topic: