Witajcie,
próbuje dynamicznie podmieniać zdjęcia (z drawable) w co drugim Fragmencie. Mam problem z napisaniem tego w metodzie onCreateView oraz w if-e. (LINIJKI 41 oraz 50)
Fragment
public class Fragment1 extends Fragment {
String stringValue;
int imagesResId;
TextView text;
String[] rbData;
RadioGroup radioButtons;
boolean mapImage;
View answer;
public Fragment1(String str, int imageView , String[] rb, boolean arg) {
this.stringValue = str;
this.imagesResId = imageView;
this.rbData = rb;
this.mapImage = arg;
}
@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);
text.setText(stringValue);
imageResId.setImageResource(imagesResId);
maps. //TUTAJ
if(mapImage){
view = inflater.inflate(R.layout.maps, container, false);
maps = view.findViewById(map_images);
maps. //TUTAJ
}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;
}
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)); //CHODZI O TEN FRAGMENT, KTÓRY WYŚWIETLANY MA BYĆ CO DRUGI I ZA KAŻDYM RAZEM Z INNYM ZDJĘCIEM
fragmentList.add(new Fragment1(getResources().getString(R.string.text_page_2), R.drawable.nature, new String[]{getResources().getString(R.string.answer4), getResources().getString(R.string.answer5),getResources().getString(R.string.answer6)},false));