findViewById() returns null for an inflated layout
问题 I have an Activity and its layout. Now I need to add a LinearLayout from another layout, menu_layout.xml . LayoutInflater inflater; inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.menu_layout, null); After this, findViewById() returns null. Is there is any solution for that? Note: I can't put both XML in one place, and using <include> also is not working. 回答1: Explanation When you inflate a