Cannot change the contents of a <include>
, but it is possible to do so in Viewgroup., because you can add and remove views his.
Where you want to replace a view on the other place a Framelayout and assign it a ID.
Create a xml for each of these views.
Create an object for each of them:
view1 = getLayoutInflater().inflate(R.layout.view1, null);
view2 = getLayoutInflater().inflate(R.layout.view2, null);
Get the reference to Framelayout:
frameLayout = (FrameLayout) findViewById(R.id.frameLayout);
Add the first view at the Framelayout:
frameLayout.addView(layout1);
When you want to change view, remove the views of Framelayout and add the new:
frameLayout.removeAllViews();
frameLayout.addView(layout2);
If you just want to put a string when the list is empty, see this reply.
I’ve done it with include. It’s not as elegant as this alternative you posted, but it works.
– Tiago P Casemiro
@Tiagopcasemiro I saw your answer, but it doesn’t change layout, it just changes visibility. However, it is a valid option/solution.
– ramaral