ListView listView = findViewById(R.id.list_view); ViewGroup parentView = (ViewGroup) listView.getParent(); // Now we can perform any actions on the parent view group. parentView.setBackgroundColor(Color.WHITE);
LinearLayout linearLayout = findViewById(R.id.linear_layout); ListView listView = new ListView(context); linearLayout.addView(listView); ViewGroup parentView = (ViewGroup) listView.getParent();In this example, we create a new ListView instance and add it to a LinearLayout using the addView() method. We then obtain a reference to the parent ViewGroup object using the getParent() method. The getParent() method is part of the android.view.View class and is available in the Android framework.