Duplicate ListFragment entries when changing orientation

给你一囗甜甜゛ 提交于 2019-12-11 18:10:07

问题


So, I'm developing an app with fragments, and everything is fine, except that when I change orientation the entries on my ListFragment duplicate like this:

And when I go back to portrait mode, the items are still duplicated; until I kill the process and restart.

To populate the list I'm using an AsyncTaskLoader, but it only runs once, when the application starts for the first time; then my adapter gets filled with the info for the rows.

I'm not using the <fragment> tag in my main.xml, the fragment is added by code in the 'parent' activity like this:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    if (savedInstanceState == null) {
        TodoListFragment fragment = new TodoListFragment();
        FragmentTransaction trans = getFragmentManager().beginTransaction();
        trans.replace(R.id.fragment_list_container, fragment,
                LIST_FRAGMENT_TAG);
        trans.commit();
    }
}

The replace was and add, but changed trying to test if it made any difference, it didn't. I also tried using the setRetainInstance(true) method, to no avail.

I'm stumped, any help would be greatly appreciated.


回答1:


You say the AsyncTaskLoader only runs when the app starts... On orientation change the app is restarting, so maybe it's running a second time?



来源:https://stackoverflow.com/questions/10622430/duplicate-listfragment-entries-when-changing-orientation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!