Obtenga todas las vistas secundarias dentro de LinearLayout a la vez

Tengo un LinearLayout , que contiene varios TextViews secundarios. ¿Cómo puedo obtener vistas secundarias de ese LinerLayout usando un bucle?

Use getChildCount() y getChildAt(int index) .

Ejemplo:

 LinearLayout ll = … final int childCount = ll.getChildCount(); for (int i = 0; i < childCount; i++) { View v = ll.getChildAt(i); // Do something with v. // … } 
  ( (ViewGroup) findViewById(android.R.id.content));// you can use this in an Activity to get your layout root view, then pass it to findAllEdittexts() method below. 

Aquí estoy iterando solo EdiTexts, si quieres todas las Vistas puedes reemplazar EditText con View.

 SparseArray array = new SparseArray(); private void findAllEdittexts(ViewGroup viewGroup) { int count = viewGroup.getChildCount(); for (int i = 0; i < count; i++) { View view = viewGroup.getChildAt(i); if (view instanceof ViewGroup) findAllEdittexts((ViewGroup) view); else if (view instanceof Edittext) { Edittext edittext = (Edittext) view; array.put(edittext.getId(), edittext); } } } 

utilizar esta

  final int childCount = mainL.getChildCount(); for (int i = 0; i < childCount; i++) { View element = mainL.getChildAt(i); // EditText if (element instanceof EditText) { EditText editText = (EditText)element; System.out.println("ELEMENTS EditText getId=>"+editText.getId()+ " getTag=>"+element.getTag()+ " getText=>"+editText.getText()); } // CheckBox if (element instanceof CheckBox) { CheckBox checkBox = (CheckBox)element; System.out.println("ELEMENTS CheckBox getId=>"+checkBox.getId()+ " getTag=>"+checkBox.getTag()+ " getText=>"+checkBox.getText()+" isChecked=>"+checkBox.isChecked()); } // DatePicker if (element instanceof DatePicker) { DatePicker datePicker = (DatePicker)element; System.out.println("ELEMENTS DatePicker getId=>"+datePicker.getId()+ " getTag=>"+datePicker.getTag()+ " getDayOfMonth=>"+datePicker.getDayOfMonth()); } // Spinner if (element instanceof Spinner) { Spinner spinner = (Spinner)element; System.out.println("ELEMENTS Spinner getId=>"+spinner.getId()+ " getTag=>"+spinner.getTag()+ " getSelectedItemId=>"+spinner.getSelectedItemId()+ " getSelectedItemPosition=>"+spinner.getSelectedItemPosition()+ " getTag(key)=>"+spinner.getTag(spinner.getSelectedItemPosition())); } }