android - Find all child views for given root view recursively -
i want find child views given root view.
public list<view> getallchildviews(view rootview) { //return child views given rootview recursively }
consumer of method pass rootview follows
//client has custom view list<view> childviews = getallchildviews(customview.getrootview()); //get root view of custom view
i can type cast rootview particular layout , children ( @ leaf level ) not sure type of root view. can scrollview or different layout
private list<view> getallchildren(view v) { if (!(v instanceof viewgroup)) { arraylist<view> viewarraylist = new arraylist<view>(); viewarraylist.add(v); return viewarraylist; } arraylist<view> result = new arraylist<view>(); viewgroup viewgroup = (viewgroup) v; (int = 0; < viewgroup.getchildcount(); i++) { view child = viewgroup.getchildat(i); //do not add parents, add child elements result.addall(getallchildren(child)); } return result; }
Comments
Post a Comment