Loop through all subviews of an Android view?

I have made a small example of a recursive function: public void recursiveLoopChildren(ViewGroup parent) { for (int i = 0; i < parent.getChildCount(); i++) { final View child = parent.getChildAt(i); if (child instanceof ViewGroup) { recursiveLoopChildren((ViewGroup) child); // DO SOMETHING WITH VIEWGROUP, AFTER CHILDREN HAS BEEN LOOPED } else { if (child != null) { … Read more

Android Custom Layout – onDraw() never gets called

By default, onDraw() isn’t called for ViewGroup objects. Instead, you can override dispatchDraw(). Alternatively, you can enable ViewGroup drawing by calling setWillNotDraw(false) in your TableView constructor. EDIT: For #2: – Initialize it in the constructor, then just call rect.set() in your onLayout() method. For #3: – Yes, as far as I’m aware the super call … Read more

Preventing/catching “IllegalArgumentException: parameter must be a descendant of this view” error

While Bruce’s answer does solve the problem, it does it in a very brutal way which harms the UX, as it will clear the focus of every view once we did a scroll. It deals with the symptom of the problem but it does not solve the actual cause. how to reproduce the problem: Your … Read more

tech