Getting some object from the layout file (say, test.xml) requiring setting this layout in the activity. For example if the button has an id "@+id/btn" then I can't get it by findViewById(R.id.btn) because it throws NullPointerException, I have to set this layout as se开发者_JAVA百科tContentLayout(test.xml) and only then get the button. The question is how can I get the object from layout file in a class which isn't an activity => I can't set layout there.
you have to use an inflater:
take a look at the doc:
inflater
as class overview says
This class is used to instantiate layout XML file into its corresponding View objects
Use inflater:
http://developer.android.com/reference/android/view/LayoutInflater.html
精彩评论