I did something similar in my code.
My goal is to have a basic box with one box, which I reuse in different actions, so I want to be able to use the activity_base_drawer layout in all actions, but change the content, inflating new views.
in my base activity (which is the activity of the navigation box), I have this protected method
protected void inflateContent(@LayoutRes int inflatedResID){ setContentView(R.layout.activity_base_drawer); LinearLayout contentContainer = ButterKnife.findById(this, R.id.content_container); getLayoutInflater().inflate(inflatedResID, contentContainer); ButterKnife.bind(this); setSupportActionBar(toolbar); setupNavDrawer(); }
I send the layout of the base navigation box to setContentView() , which has a linear layout, which is the container that I want to inflate new layouts in it for each action, which extends my base activity
As you can see, LinearLayout contentContainer uses findById not @BindView . I have to do it this way because I need to inflate the view in the content container before I call ButterKnife.bind(this);
After finding the layout of the content container, I inflate it using getLayoutInflater().inflate(inflatedResID, contentContainer);
Then I call ButterKnife.bind(this);
Finally, some customization methods depend on layouts that are associated with @BindView in the base activity class.
and in any expanding action onCreate () looks like where I send the id of the layout I want to inflate to inflateContent()
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); inflateContent(R.layout.content_main); }