Example:
I have 3 TextViews
and its id's
:
TextView tv1 -> id: "um"
TextView tv2 -> id: "dois"
TextView tv3 -> id: "tres"
I would like to group them in some way that can access them through the group, eg:
ViewGroup vg;
vg.addView(tv1);
vg.addView(tv2);
vg.addView(tv3);
TextView tv11 = (TextView) vg.findViewById("um");
TextView tv22 = (TextView) vg.findViewById("dois");
TextView tv33 = (TextView) vg.findViewById("tres");
Is it possible to do this? I tried ViewGroup
, but I could not.
SOLUTION:
From the reply of @ramaral, my code looks like this:
for (int i = 0; i < 7; i++) {
ViewGroup vg = (ViewGroup) adapter.getViewAtPosition(i); //pega os layouts
for (int j = 0; j < vg.getChildCount(); j++) { //percorre seus elementos
View v = vg.getChildAt(j);
if (v instanceof ViewGroup) { //pega tudo que for ViewGroup, inclusive outros layouts
for (int h = 0; h < ((ViewGroup) v).getChildCount(); h++) { //percorre novamente
View v2 = ((ViewGroup) v).getChildAt(h);
if (v2 instanceof TextView) { //pega tudo que for TextView
map.put(v2.getId(), (TextView) v2); //adiciona as TextViews no HashMap
}
}
}
}
}
I now have access to TextView's
of various layouts and their id's
(a1, a2 ... a70)
are in order.