android studio clear views of layout

Java
//either this
layout.removeAllViews();

//or this
((LinearLayout) findViewById(R.id.layout)).removeAllViews();
Source

Also in Java: