Get nodes from a xml layout in Android

Using a layout template ex: temp.xml I’m creating a new View with LayoutInflater and I add that View to my MainActivity layout:

inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View newView = inflater.inflate(R.layout.temp, null, false);

teml.xml has the following structure:

LinearLayout -> LinearLayout -> (two children) ImageView & TextView 

How do I extract from the newView the ImageView and TextView elements so I can add Text and a Image to them ?

Do I have to TypeCast newView to Node or NodeList?


You can use findViewById() on the newView

TextView textView = newView.findViewById(;
ImageView imageView = newView.findViewById(;
Source: stackoverflow
The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .