Non ci si dovrebbe aspettare un array di viste da questo metodo, poiché la firma del metodo indica che restituirà una vista singola.
public final View findViewWithTag (Object tag)
Tuttavia, ciò che si può fare è quello di ottenere il layout come ViewGroup
e poi scorrere tutti i punti di vista del bambino per trovare la propria vista desiderata facendo un look-up sulla loro etichetta. Per esempio:
/**
* Get all the views which matches the given Tag recursively
* @param root parent view. for e.g. Layouts
* @param tag tag to look for
* @return List of views
*/
public static List<View> findViewWithTagRecursively(ViewGroup root, Object tag){
List<View> allViews = new ArrayList<View>();
final int childCount = root.getChildCount();
for(int i=0; i<childCount; i++){
final View childView = root.getChildAt(i);
if(childView instanceof ViewGroup){
allViews.addAll(findViewWithTagRecursively((ViewGroup)childView, tag));
}
else{
final Object tagView = childView.getTag();
if(tagView != null && tagView.equals(tag))
allViews.add(childView);
}
}
return allViews;
}
waqas Ho una domanda simile. puoi dirmi cosa fare? http://stackoverflow.com/questions/17061833/androidone-button-id-for-many-buttons-on-expandable-list-children – user2468835
Vedi: http://android-wtf.com/2013/06/ how-to-easy-traverse-any-view-hierarchy-in-android/ – Jamol