I have a Horizontal scrollview in a fragment of which I am inflating the same layout multiple times (i.e. about 300) in a loop on ActivityCreated method.
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
for (int i = 0; i < myData.size(); i++) {
View view = getActivity().getLayoutInflater().(R.layout.item, null);
parentLayout.addView(view, params);
}
}
I have noticed some performance issues on inflation on this loop, i.e. there is a delay before the fragment is shown.
Not sure what the best approach to tackle this, and what is the best process for inflating multiple layouts in a loop?
If I could do it asynchronously, that might be an option?
This is precisely the situation for which you should be using an AdapterView. In this case, a ListView is probably the best fit. It does a lot of smart things such as only creating views when the will be visible and recycling views as they scroll out of visibility.