Java tutorial
//package com.java2s; import android.view.View; import android.view.ViewGroup; public class Main { public static void addViewOnly(ViewGroup layout, View view) { try { if (layout.getChildCount() > 0) { layout.removeAllViews(); } layout.addView(view); } catch (Exception e) { // e.printStackTrace(); } } }