Java tutorial
//package com.java2s; import android.view.View; import android.view.ViewGroup; public class Main { public static void swapViewGroupChildren(ViewGroup viewGroup, View firstView, View secondView) { int firstIndex = viewGroup.indexOfChild(firstView); int secondIndex = viewGroup.indexOfChild(secondView); if (firstIndex < secondIndex) { viewGroup.removeViewAt(secondIndex); viewGroup.removeViewAt(firstIndex); viewGroup.addView(secondView, firstIndex); viewGroup.addView(firstView, secondIndex); } else { viewGroup.removeViewAt(firstIndex); viewGroup.removeViewAt(secondIndex); viewGroup.addView(firstView, secondIndex); viewGroup.addView(secondView, firstIndex); } } }