片段到片段的事务速度较慢

7

我有一个带有左侧屏幕ListViewfragment...

无论何时用户点击ListView中的任何一项,我都会在右侧显示fragment...

下面是我使用事务的方式:

FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
SiteDetailsFragmentActivity fragment = new SiteDetailsFragmentActivity();
fragment.setArguments(args);
fragmentTransaction.replace(R.id.fragment1, fragment);
fragmentTransaction.commit();

为什么ds交易如此缓慢?

2
事务并不慢,可能是因为ListView需要时间来加载数据。尝试在fragmentonCreateView()之后使用AsyncTask来加载ListView数据。 - The Heist
列表视图是否包含图片?如果有,请检查图片的大小。 - sunil
@T-rush - 当所有数据都加载完成后,我才允许用户点击项目... - Balwinder SIngh
这与用户的点击无关。我的建议是在onCreateView()执行后,在后台加载正确的“Fragment”数据。 - The Heist
@OAEI没有帮助我。 - Ravi
你的列表项或者背景,或者你的Fragment中是否有任何图片?请检查一下。 - Rahul Kushwaha
1个回答

2
最初的回答:有一些小技巧可能会有用。
  • if you have lots of work like network calls in your fragment try to call them after your onCreateView() function. i.e you can use onStart() or onResume() functions.Also, try to use multiThread.

  • if you have Image Loading try to reduce image qualities or its size.reduce image size

  • Also avoid animation in replacing your fragments.

    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接