Самое банальное вот так:
@Override
protected void onPostExecute(Spanned spanned) {
super.onPostExecute(spanned);
title.setText(strTitle);
textView.setText(spanned);
for (List<String> id : ids) {
VideoFragment f = VideoFragment.newInstance(id);
FrameLayout frameLayout = new FrameLayout(NewsContent.this);
frameLayout.setTag(id);
linearLayout.addView(frameLayout);
getSupportFragmentManager().beginTransaction().replace(frameLayout.getId(), f).commit();
}
progressDialog.dismiss();
}
}
activity_main.xml<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/scrollContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"/>
</ScrollView>
</RelativeLayout>
MainActivity.javapublic class MainActivity extends AppCompatActivity {
LinearLayout linearLayout;
String[] ids = new String[]{"1", "2", "3", "4", "5"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
linearLayout = (LinearLayout) findViewById(R.id.scrollContainer);
int position = 0;
for (String id : ids) {
FrameLayout fm = new FrameLayout(this);
fm.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 500));
linearLayout.addView(fm);
fm.setId(++position);
BlankFragment fragment = BlankFragment.newInstance(id);
getFragmentManager().beginTransaction().replace(position, fragment, id).commit();
}
}
}
fragment_blank.xml<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/hello_blank_fragment" />
</FrameLayout>
BlankFragment.javapublic class BlankFragment extends Fragment {
private static final String ARG_PARAM1 = "param1";
private String mParam1;
private TextView title;
public static BlankFragment newInstance(String param1) {
BlankFragment fragment = new BlankFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
fragment.setArguments(args);
return fragment;
}
public BlankFragment() {}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_blank, container, false);
title = (TextView) v.findViewById(R.id.title);
title.setText(mParam1);
return v;
}
}