This is really strange issue, I was scratching my head before posting this.
Straight to the problem: I have a LinearLayout
inside a ScrollView
in my activity and I use the FragmentManager
to pump my Fragments into the layout, each one has its unique Tag and UI, and the code works great.
...
for(object o: my_data)
{
MyFragment f = MyFragment.newInstance(o.blah());
Log.w("app","adding object "+o.tag_name()+"to the list");
transaction.add(R.id.my_linear_layout_id, f, o.tag_name());
}
transaction.commit();
Say I have 3 objects with tag "1","2","3" in my_data. The result of above codes will display my Fragments in right order 1,2,3. In my UI they are 1,2,3 from top of the LinearLayout to bottom. like
1 2 3
Strange issue comes when I try to remove all Fragments and add them with the same code again.(Like refresh)
...
ft = frag_manager.beginTransaction();
for(object o: my_data)
{
ft.remove(frag_manager.findFragmentbyTag(o.tag_name()));
}
ft.commit();
The result would become reversed on my LinearLayout, from top to bottom:
3 2 1
Although my Log shows that 1,2,3 has been added to the layout, respectively.
I tried and test the code many times and found that the result is always correct at the FIRST time, but after any remove-all operation, the new result will be reversed and there will be no longer correct result. What could be the reason behind this issue? What am I missing? It's crazy imo.