在我的应用中,有一个包含四个不同标签的viewpager。在每个选项卡中,嵌套ScrollView中有五个不同的片段,每个片段都会加载一个recyclerview。一切都加载但问题是当回收者视图附加大量数据时,数据需要很长时间才能加载。有时,加载需要10秒以上的时间,当有人需要等待很长时间时,它会非常恼人。请帮我解决这个问题。在每个选项卡中,下面提供的相同片段加载但具有不同的数据。
我的代码如下所示。
public class MyViewPagerFragment extends Fragment implements
View.OnClickListener {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.my_fragment_layout, container, false);
android.support.v4.app.FragmentManager manager = getChildFragmentManager();
android.support.v4.app.FragmentTransaction transaction = manager.beginTransaction();
BatsmanHelper.addNotBattedBatsmanFromPlayingXI(context, team, team.getBatsmans_list(), match);
FragmentOneWithRecyclerView fragment1 = new FragmentOneWithRecyclerView();
Bundle bundle1 = new Bundle();
// put some data in the bundle
recyclerView.setArguments(bundle1);
transaction.add(R.id.fragment1_container,
fragment1).addToBackStack(null
);
FragmentTwoWithRecyclerView fragment2 = new
FragmentTwoWithRecyclerView();
bundle1 = new Bundle();
// put some data in the bundle
fragment2.setArguments(bundle1);
transaction.add(R.id.fragment2_container,
fragment2).addToBackStack(null
);
FragmentThreeWithRecyclerView fragment3 = new
FragmentThreeWithRecyclerView();
bundle1 = new Bundle();
// put some data in the bundle
fragment3.setArguments(bundle1);
transaction.add(R.id.fragment3_container,
fragment3).addToBackStack(null
);
FragmentFourWithRecyclerView fragment4 = new FragmentFourWithRecyclerView();
bundle1 = new Bundle();
// put some data in the bundle
fragment4.setArguments(bundle1);
transaction.add(R.id.fragment4_container,
fragment4).addToBackStack(null
);
transaction.commit();
return view;
}
}
答案 0 :(得分:0)
也许有两个问题:
您的recyclerView中的项目可能需要很长时间才能加载。 (然后你必须优化你的适配器)
而不是使用bundle,其中的片段构建了这样的方法:
public void setCustomData(Object data){
this.data = data ;
}
然后只使用fragment.setCustomData(yourStuffs);