In my activity, I am setting the layout activity_main onCreate. I am then wanting to inflate my CardView for each of the items in my array.
So far, I\'ve got every
You're passing in null
as the parent ViewGroup
parameter to inflate()
. This will cause all layout_*
attributes to be ignored, as the inflater has no idea which attributes are valid for the container in which it will be placed (i.e. it has no idea which LayoutParams
type to set on the View
).
View child = getLayoutInflater().inflate(R.layout.activity_main_card, null);
should be
View child = getLayoutInflater().inflate(R.layout.activity_main_card, item, false);
For more info, see this great article about it -- it's a common mistake.