开发者

Layout id conflict in android

开发者 https://www.devze.com 2023-04-11 15:08 出处:网络
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)

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号