Let me explain again.
When you use setContentView(R.layout.activity_main )
, the layout R.layout.activity_main
will be inflated and associated to your activity. If you want to retrieve a View from that layout, you just call findViewById(R.id.MyId);.
But if your View is not inside the layout you passed to setContentView()
, you will have a NullPointerException
.
Besides, if you inflate a layout using an inflater then call inflatedView.findViewById(R.id.MyId)
Hope you will understand now.