Android gets the components in view

Source: Internet
Author: User
<span id="Label3"></p><pre class="best-text mb-10"><pre class="best-text mb-10">This view can be turned into a viewgroup object, then through Getchildat (0), getchildat (1)<br><br>AddView may error after obtaining: illegalstateexception:the specified child already have a parent problem resolution</pre></pre><pre>Recently encountered a very troublesome problem, using Viewpager to dynamically add pages or delete pages when there is a problem (java.lang.IllegalStateException:The specified child already have a Parent. You must call Removeview () on the Child's parent First) and found a solution on STACKOVERFLOW. (http://stackoverflow.com/questions/22936886/java-lang-illegalstateexception-while-using-viewpager-in-android)<span style="color: #000000;"><span style="color: #000000;">the original text was: the problem is, the Your adapters method instantiateitemyou call Container.addview (v), But every View can has O Nly One parent,so It can is added only one time to a container via AddView (...). When you open the popup the first time, everything works, because VDOESN</span></span>' t has a parent that Time. But when you open your Popupwinow the second time,<span style="color: #000000;"><span style="color: #000000;">it adds the view again to the Container. That cerates the Error. Try to destroy the view</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span><span style="color: #000000;"><span style="color: #000000;">you close the popup view or remove all children views from it withcontainer.removeallviews () solution is to use in Instantiateitem as Bottom Way: ViewGroup Parent</span></span>=<span style="color: #000000;"><span style="color: #000000;">(viewgroup) v.getparent ();</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>(parent! =<span style="color: #0000ff;"><span style="color: #0000ff;">NULL</span></span><span style="color: #000000;"><span style="color: #000000;">{parent.removeallviews ();} Container.addview (v), many times in the middle try to get close to the answer, but habitually to the v.getparent () forced into view, View does not have the Removeview () method, so that give up this method, later to think more, think of the solution if it is not the result of their own, we must check again, it is likely that some small place did not notice. Struggle</span></span></pre><p><p></p></p><p><p>Android gets the components in view</p></p></span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.