문제

I'd need help with a simple implementation of a ViewFlipper. The flipper works perfect when I inflate child views "ws.addView(childView)" in the onCreate of the activity.

I run into a problem when I want to remove all children from the flipper and add another bunch of them via addView(child) method. I am trying to call the onFinishInflate() and invalidate() methods on the flipper which do not seem to produce the desired effect of refreshing the content of the flipper. The view of the flipper is blank. I checked if the flipper contains children after the addView loop and in my case the number is > 1. Maybe I'm missing something. Hope somebody can help me.

                ws.removeAllViews();
                ArrayList<View> childViews = getAllChildrenFromSomewhere();
                for (View childView : childViews) {
                    ws.addView(childView);
                }
                ws.onFinishTemporaryDetach();

                ws.onFinishInflate();
                ws.invalidate();    

best regards

도움이 되었습니까?

해결책

I was able to find the answer to my question. I was removing all children from the ViewFlipper and the next step was to add new children to the ViewFlipper. Removing all children and invalidating the view was resulting in a blank view, due to no child was selected. By only adding new children and again invalidating the view, the ViewFlipper stayed blank. By using ws.showNext() after ws.invalidate(), the first child from the new children is shown and the ViewFlipper works as expected. Hope this helps.

            ws.removeAllViews();
            ArrayList<View> childViews = getAllChildrenFromSomewhere();
            for (View childView : childViews) {
                ws.addView(childView);
            }
            ws.onFinishTemporaryDetach();

            ws.onFinishInflate();
            ws.invalidate();  
            // show the first childView
            ws.showNext();

best regards and happy coding :-)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top