• Call removeView() on the child's parent first


    extends:http://stackoverflow.com/questions/6526874/call-removeview-on-the-childs-parent-first

    Exception:

    java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
               at android.view.ViewGroup.addViewInner(ViewGroup.java:1976)
               at android.view.ViewGroup.addView(ViewGroup.java:1871)
               at android.view.ViewGroup.addView(ViewGroup.java:1828)
               at android.view.ViewGroup.addView(ViewGroup.java:1808)
    Solution:
    
    ((ViewGroup)scrollChildLayout.getParent()).removeView(scrollChildLayout); 

    Use the child element to get a reference to the parent. Cast the parent to a ViewGroup so that you get access to the removeView method and use that.
         LinearLayout layout = initLayout();
            for (int i = 0; i < items.size(); i++) { 
                View view = items.get(i);
                ((ViewGroup) view.getParent()).removeView(view);
                layout.addView(view, lpLabel);
            }
            mLayout.addView(layout);

  • 相关阅读:
    JavaSE--注解
    JavaSE--【JAVA】unicode为12288字符
    Spring--Spring 注入
    Spring--@configuration 和 @Bean
    JavaEE--分布式对象
    JavaSE--jdom解析之bom
    JavaEE--分布式与集群
    JavaEE--调用 WSDL -- httpclient 4.x.x
    JavaSE--RMI初识
    Redis--初识Redis
  • 原文地址:https://www.cnblogs.com/niray/p/4415516.html
Copyright © 2020-2023  润新知