ViewGroup parentLayout = (ViewGroup) findViewById(R.id.parent_layout); TextView myTextView = (TextView) parentLayout.findViewById(R.id.my_text);
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.my_linear_layout); TextView textView1 = (TextView) linearLayout.findViewById(R.id.textview1); TextView textView2 = (TextView) linearLayout.findViewById(R.id.textview2); if (condition) { textView1.setText("Condition met"); } else { textView2.setText("Condition not met"); }In this example, we first get the reference to the LinearLayout using findViewById, casting it to a LinearLayout. Then, we use findViewById again to get references to each of the TextViews within the LinearLayout. Finally, we check a condition and set the text of one of the TextViews accordingly. The package library for the findViewById method is in the android.view package.