Issue
I have a layout, where the top quarter is always the same, but the lower part needs to use a "sublayout" specific to the represented object's state.
Can I achieve this, using a "parent" layout and several state-specific layouts?
(The state-specific layouts could either be embedded in the parent layout at run-time, or each child layout could "include" the parent layout.)
Solution
This turned out to be straightforward, once I'd added a placeholder-view to the LinearLayout (at index 2).
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ViewGroup linearLayout = (ViewGroup) view.findViewById(R.id.linearLayout);
int stateLayout;
switch (peer.commState) {
case IDLE:
stateLayout = R.layout.peer_idle;
break;
case REQUEST_MADE:
stateLayout = R.layout.peer_request_made;
break;
...
default:
throw new AssertionError();
}
linearLayout.removeViewAt(2);
View stateView = inflater.inflate(stateLayout, linearLayout, false);
linearLayout.addView(stateView);
Answered By - fadedbee
Answer Checked By - Dawn Plyler (JavaFixing Volunteer)