Dato un nuovo schermo in Android vorrei scorrere tutti i viewgroup e le viste per scoprire tutti i pulsanti, campi di testo, spinner, ecc ... è possibile?Iterating through viewgroup
5
A
risposta
7
ottengo il numero di visualizzazioni e quindi utilizzare tale come un contatore chiamare getChildAt (int index)
4
Questa domanda potrebbe essere stato a lungo una risposta, ma ho scritto questa funzione ricorsiva per impostare onClickListeners per tutti i pulsanti che trovo nel mio layout, ma potrebbe essere riproposto:
private void recurseViews(ViewGroup v) {
View a;
boolean isgrp = false;
for(int i = 0; i < v.getChildCount(); i++) { //attach listener to all buttons
a = v.getChildAt(i);
if(a instanceof ViewGroup) setcl((ViewGroup) a);
else if(a != null) {
//do stuff with View a
}
}
return;
}
EDIT: Lanciare una Vedi come ViewGroup non solleva un'eccezione, come avevo pensato in precedenza, in modo che il codice è molto più breve ora
Problemi correlati
- 1. Iterating through array - java
- 2. Iterating Through N Level Children
- 3. Iterating through all JDK classes
- 4. Iterating through Arraylist con classi estese
- 5. C#: Iterating through a data table: Rows, Select() o AsEnumerable()
- 6. Android View e ViewGroup
- 7. rails has_many: through has_many: through
- 8. Come usare viewGroup in Android
- 9. Iterating circular way
- 10. Iterating Backbone Collection
- 11. Iterating over asyncio.coroutine
- 12. Iterating over eterogeneous container
- 13. Iterating over a lvalue
- 14. Iterating over Typescript Map
- 15. Clone textview per aggiungerlo a un ViewGroup
- 16. Gestione del focus di ViewGroup personalizzato
- 17. Android: ottieni il Viewgroup dalla vista?
- 18. Iterating on a tuple ... again
- 19. Iterating over a map entryset
- 20. Append to List while Iterating
- 21. Rails polymorphic has_many: through
- 22. Iterate through DataSet
- 23. C#: Cycle through encodings
- 24. loop through JPanel
- 25. activerecord find through association
- 26. Django M2MFields 'through' widgets
- 27. Python 'except' fall-through
- 28. loop through sottocartelle
- 29. Has_Many: Through o: finder_sql
- 30. Iterate through 2 Lists
controllare questa risposta da Romain Guy: http://stackoverflow.com/questions/2597230/loop-through-all-subviews-of-an-android-view –