Witajcie,
udało mi się przesłać do Fragmentu text
i drawable
z MainActivity. Jak przesłać string array
do Fragmentu (w metodzie onCreateView) i wyświetlić dynamicznie w radioButtonach?
MainActivity
frags = new ArrayList<>();
frags.add(new Fragment1("Text1", R.drawable.nature2, new String[]{"option 1", "option 2", "option 3"}));
frags.add(new Fragment1("Text2",R.drawable.nature4, new String[]{"option 4", "option 5", "option 6"}));
Fragment
public class Fragment1 extends Fragment {
public Fragment1() {
}
String stringValue;
int imagesResId;
TextView text;
String[] rbData;
View answer;
public Fragment1(String str, int imageView , String[] rb) {
this.stringValue = str;
this.imagesResId = imageView;
this.rbData = rb;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Log.i("x","onCreateViewFragment");
View view = inflater.inflate(R.layout.fragment1, container, false);
text = view.findViewById(R.id.textView);
ImageView imageResId = view.findViewById(image);
answer =(RadioGroup) view.findViewById(R.id.radioGroup);
text.setText(stringValue);
imageResId.setImageResource(imagesResId);