The android.view.ViewGroup removeViewAt method is a part of Android's view package library. It allows you to remove a specified child view from a group of views, based on its index in the group. Here are some code examples:
Example 1: Removing a View from a LinearLayout
LinearLayout linearLayout = findViewById(R.id.my_linear_layout); //get reference to the LinearLayout
View viewToRemove = linearLayout.getChildAt(2); //get reference to the view to remove
linearLayout.removeViewAt(2); //remove the view from the LinearLayout
In this example, we get a reference to a LinearLayout, then get a reference to the 3rd child view in the group (index 2), and remove it using the removeViewAt() method.
Example 2: Removing a View from a RelativeLayout
RelativeLayout relativeLayout = findViewById(R.id.my_relative_layout); //get reference to the RelativeLayout
View viewToRemove = relativeLayout.getChildAt(1); //get reference to the view to remove
relativeLayout.removeViewAt(1); //remove the view from the RelativeLayout
This example is similar to the first, but we get a reference to a RelativeLayout instead of a LinearLayout, and remove the 2nd child view from the group (index 1).
The package library for android.view is part of the Android framework, so it is part of the core Android operating system.
Java ViewGroup.removeViewAt - 16 examples found. These are the top rated real world Java examples of android.view.ViewGroup.removeViewAt extracted from open source projects. You can rate examples to help us improve the quality of examples.