Tak wygląda to na chwilę obecną
Mam listę w MainActivity
fragmentList = new ArrayList<>();
fragmentList.add(new Fragment1(getResources().getString(R.string.text_page_1), R.drawable.swans, new String[]{getResources().getString(R.string.answer1), getResources().getString(R.string.answer2),getResources().getString(R.string.answer3)},false));
fragmentList.add(new Fragment1(null, R.drawable.image_file, null, true));
fragmentList.add(new Fragment1(getResources().getString(R.string.text_page_2), R.drawable.nature, new String[]{getResurces().getString(R.string.answer5),getResources().getString(R.string.answer6)},false));
Którą przekazuje tu
public class PagerAdapter extends FragmentStatePagerAdapter {
List<Fragment> fragmentList;
public PagerAdapter(FragmentManager fm, List<Fragment> fragmentList) {
super(fm);
this.fragmentList = fragmentList;
}
@Override
public Fragment getItem(int position) {
return fragmentList.get(position);
}
@Override
public int getCount() {
return fragmentList.size();
}
}
Problem tylko, że nie mogę tego wyświetlić we Fragmencie :(
public class Fragment1 extends Fragment {
String stringValue;
int imagesResId;
TextView text;
String[] rbData;
RadioGroup radioButtons;
boolean mapImage;
View answer;
public static Fragment1 newInstance (String str, int imageView , String[] rb, boolean arg) {
Fragment1 fragment = new Fragment1();
Bundle args = new Bundle();
args.putString("str", str);
args.putInt("image_resid", imageView);
args.putStringArray("rb", rb);
args.putBoolean("arg", arg);
fragment.setArguments(args);
return fragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Log.i("x","onCreateViewFragment");
View view = inflater.inflate(R.layout.fragment_1, container, false);
text = view.findViewById(R.id.textView);
ImageView imageResId = view.findViewById(image);
answer = view.findViewById((R.id.radioGroup));
ImageView maps = view.findViewById(map_images);
if(mapImage){
view = inflater.inflate(R.layout.maps, container, false);
maps = view.findViewById(map_images);
}else{
view = inflater.inflate(R.layout.fragment_1, container, false);
text = view.findViewById(R.id.textView);
radioButtons = view.findViewById(R.id.radioGroup);
text.setText(stringValue);
imageResId.setImageResource(imagesResId);
}
if (answer != null) {
for (int i = 0; i < radioButtons.getChildCount(); i++) {
((RadioButton) radioButtons.getChildAt(i)).setText(rbData[i]);
}
}
return view;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
Log.i("x","onActivityCreatedFragment");
super.onActivityCreated(savedInstanceState);
}
@Override
public void onCreate(Bundle savedInstanceState) {
Log.i("x","onCreateFragment");
super.onCreate(savedInstanceState);
Bundle args = getArguments();
stringValue = args.getString("str");
imagesResId = args.getInt("image_resid");
rbData = args.getStringArray("rb");
mapImage = args.getBoolean("arg");