private void initTopContainer( FrameLayout frameLayout, LayoutInflater layoutInflater, ViewGroup viewGroup) { LinearLayout linearLayout = new LinearLayout(getActivity()); linearLayout.setOrientation(LinearLayout.VERTICAL); View v = layoutInflater.inflate(R.layout.layout_card, linearLayout); CardViewHolder cardViewHolder = new CardViewHolder(v); cardViewHolder.setCardViewModel(new CardViewModel(post)); ViewGroup cv = (ViewGroup) ((ViewGroup) layoutInflater.inflate(R.layout.like_button, linearLayout)) .findViewById(R.id.empty_card); initCardView((ViewGroup) cv.findViewById(R.id.like_container)); frameLayout.addView(linearLayout); }