I am making SKD for Automation. So my needs are slightly different that normal app development.
Requirement: Get ViewHierarchy of current activity. Problem: I get it correct when Spinner is not open. I do not get the details of spinner when its open.
I use following code to get hierarchy. Questions is: Does Spinner get hosted in a different window which is why I am not getting it? What would be the way to get it?
//This is how I start recursion to get view hierarchy
View view = getWindow().getDecorView().getRootView();
if (view instanceof ViewGroup) {
ViewGroup group = (ViewGroup) view;
dumpViewHierarchyWithProperties( group, 0);
}
//Functions to get hierarchy
private void dumpViewHierarchyWithProperties(ViewGroup group,int level) {
if (!dumpViewWithProperties(group, level)) {
return;
}
final int count = group.getChildCount();
for (int i = 0; i < count; i++) {
final View view = group.getChildAt(i);
if (view instanceof ViewGroup) {
dumpViewHierarchyWithProperties((ViewGroup) view, level + 1);
} else {
dumpViewWithProperties(view, level + 1);
}
}
}
private boolean dumpViewWithProperties(View view,int level) {
//Add to view Hierarchy.
return true;
}