Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am having problem with xamarin listview.
i can't seem to view my list xaml page more than once. i am using below code to load it from viewmodel but when i go to the page the second time it freezes and most times it brings an error about
Java.Lang.IllegalStateException: 'The specified child already has a parent. You must call removeView() on the child's parent first.'
and the problem is all solutions on the intternet talks about solving an adroid app but this is not android specific but xamarin so please i don't know how to solve it. below is my viewmodel i use to bind list to viewmodel.

public class MyDiscoveriesViewModel
   {
       public List<Discover> Discoveries { get; set; }
       public MyDiscoveriesViewModel()
       {
           Discoveries = Discover.AllDiscover().ToList();

       }
   }


please what am i doing wrong because i have tried using observablecollection but it doesn't bind to listview

What I have tried:

protected override void OnCreate(Bundle savedInstanceState)
      {
          base.OnCreate(savedInstanceState);

          Xamarin.Essentials.Platform.Init(this, savedInstanceState);
          global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
          Android.Views.View v;
          ViewGroup Parent = (ViewGroup)v.Parent();
          LoadApplication(new App());
      }
Posted
Updated 17-Dec-21 20:05pm

1 solution

It doesn't matter if this is Android or not: the error message is very explicit: The child control already has a parent. That means very simply that it is already displaying in a container object and cannot be added to a second container, any more than an apple can be in two different bags of fruit at the same time, or you can be in two different houses simultaneously.

That's not something we can even start to "fix" for you - you are making a fundamental mistake somewhere in yoru code, and we don't have any access to the whole thing to even try.

So go back to the previous working version and look closely at what you changed since then. We can't do that for you!
 
Share this answer
 
Comments
[no name] 18-Dec-21 10:04am    
i saw the solution somewhere in the internet. someone was doing what i was doing which is using swipeview and removing that fix the problem. thanks for your time.
OriginalGriff 18-Dec-21 10:54am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900