TextView myTextView = findViewById(R.id.my_text_view); ViewGroup parentView = (ViewGroup) myTextView.getParent();
TextView myTextView = findViewById(R.id.my_text_view); View parentView = myTextView.getParent(); if (parentView instanceof LinearLayout) { // Do something if the parent is a LinearLayout } else if (parentView instanceof ConstraintLayout) { // Do something if the parent is a ConstraintLayout }In this example, the getParent() method is called on a TextView object again. The class of the returned parent view is checked using an instanceof check, and different actions are taken based on the type of the parent view. The getParent() method is part of the android.widget.TextView class, which is included in the Android framework's core library.