0

Hi in the below code passing string value to another fragment. In the second Fragment getting the value. Now I want to set that value to my spinner. can any one help me how to set the value to spinner.

OneFragement.java:

Fragment fragment = new SecondFragement();
        Bundle args = new Bundle();
 args.putString("task_types", task_types);//training
fragment.setArguments(args);
        loadFragment(fragment);

SecondFragement.java:

    String task_types = getArguments().getString("task_types");//training
    spinnertaskType=rootView.findViewById(R.id.task_type);

 task_typelist.clear();
            String task_types = getArguments().getString("task_types");
            task_typelist.add(task_types);
              ArrayAdapter<String> dataAdapter1 = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, task_typelist);
             dataAdapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            spinnertaskType.setAdapter(dataAdapter1);
jyo srijyo
  • 53
  • 6

1 Answers1

0

In this code you will have just one item in your string, you should add task_types to your arraylist. You shouldn't clear your arraylist before that.

MMG
  • 3,226
  • 5
  • 16
  • 43