Instead of prefixing id’s in xml, is it possible to specify the particular layout in code? For example, if I have 3 layouts, each with a button that has an id of “btn”. Is it possible to specify which layout to findViewById(R.id.btn) in?
Instead of prefixing id’s in xml, is it possible to specify the particular layout
Share
The basic context is defined via
setContentView(R.lyaout.my_layout). If you inflate another layout usingLayoutInflater.inflate()you get a layout object, lets call itbuttonLayout. You can now differ betweenthis.findViewById(R.id.button)andbuttonLayout.findViewById(R.id.button)and both will give you different button references.