Adding Fragments Using For Loop
I am very new to programming an android as well. I am trying to add fragments using for loop. Lets say I would like to repeat fragment n-times. for (int i = 0; i < lengt
Solution 1:
First, I never use Xamarin, but can't you slightly change your code to this? I don't see the point of beginning a new transaction for each and every fragment. Same goes for committing.
FragmentTransactionfragmentTransaction=this.FragmentManager.BeginTransaction();
for (inti=0; i < length; i++)
{
Fragmentfrag= _fragments[1];
fragmentTransaction.Add(Resource.Id.frameForAddressFragment, frag);
fragmentTransaction.AddToBackStack(null);
}
fragmentTransaction.Commit();
Second, I don't know if it's a mistake, but you have written Fragment frag = _fragments[1];
. I assume you meant Fragment frag = _fragments[i];
Third, is there any problem with your code? As a reminder, your "Resource.Id.frameForAddressFragment" is supposed to be the ID of the container in which you want to add the fragment.
Last, what do you mean by this?
I think I have to declare Fragment for every loop with new name?
What "new name" are you talking about?
Post a Comment for "Adding Fragments Using For Loop"