title: Refreshing a recyclerview in a fragment
body: <p>I have 2 activities: RoutineViewer and ExerciseViewer. Both activities contain fragments that are sub-classes of <code>ParentFragment.java</code>.</p>
  
  <p>RoutineViewer's fragment (RoutineViewerFragment) is displaying a recyclerview. The recyclerview's data is from a static ArrayList in <code>ParentFragment.java</code>.</p>
  
  <p>From RoutineViewerFragment, I can start the ExerciseViewer activity, and the fragment inside it (ExerciseViewerFragment) is used to make changes to <code>customRoutineExercise</code> in ParentFragment.java. After making the changes in ExerciseViewerFragment, I can call <code>requireActivity().finish()</code> on ExerciseViewer.java, which will take me back to RoutineViewerFragment. However, my problem is that the data in RoutineViewerFragment is not reflecting the changes I made in ExerciseViewerFragment.  </p>
  
  <p>Some solutions I have tried (but didn't work in this case) from looking at other similar problems:</p>
  
  <pre><code>// In RoutineViewerFragment onResume() with if else conditions
  mAdapter.notifyItemChanged(// insert relevant position);
  </code></pre>
  
  <pre><code>// In RoutineViewer.java onResume() with if else
  getSupportFragmentManager().beginTransaction.detach(currentfragment).attach(currentfragment).commit()
  </code></pre>
  
  <p>I'm guessing that the reason why <code>mAdapter.notifyItemChanged(position)</code> isn't working is because I'm not directly passing the static <code>customRoutineExercise</code> in the constructor of mAdapter, but rather a value of the HashMap instead.</p>
  
  <p>As for the <code>.detach().attach()</code>, I've read that it forces the <code>onCreateView()</code> to run again, which theoretically should refresh the recyclerview with the updated data, but it isn't.</p>
  
  <p>I've left the important code segments below. Any help is appreciated, thanks!</p>
  
  <p><strong>ParentFragment.java</strong></p>
  
  <pre><code>protected static int selectedCustomRoutine;
  protected static int selectedCustomExercise;
  protected static ArrayList&lt;customRoutine&gt; customRoutineInfo = new ArrayList&lt;&gt;();
  protected static HashMap &lt;Integer, ArrayList&lt;customExercise&gt;&gt; customRoutineExercise = new HashMap&lt;&gt;();
  </code></pre>
  
  <p><strong>RoutineViewer.java</strong></p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_routine_viewer);
  
      Intent intent = getIntent();
      routineType = intent.getStringExtra("routineType");
      routinePosition = intent.getIntExtra("routinePosition", 0);
  
      selectedFragment = new RoutineViewerCustomFragment(routinePosition);
      getSupportFragmentManager().beginTransaction().replace(R.id.routineV_fragment_container, selectedFragment).commit();
      break;
  
      }
  </code></pre>
  
  <p><strong>RoutineViewerFragment.java</strong></p>
  
  <pre><code>private int routinePosition;
  
  public RoutineViewerCustomFragment(int routinePosition) {
      // constructor
      this.routinePosition = routinePosition;
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      View rootView = inflater.inflate(R.layout.fragment_routine_viewer_custom, container, false);
      buildRecyclerView(rootView);
      return rootView;
  }
  
  // other code
  
  private void buildRecyclerView(View rootView) {
      mRecyclerView = rootView.findViewById(R.id.recyclerView);
      mRecyclerView.setHasFixedSize(true);
      mLayoutManager = new LinearLayoutManager(getActivity());
      mAdapter = new RoutineViewerCustomAdapter(customRoutineExercise.get(routinePosition));
  
      mRecyclerView.setLayoutManager(mLayoutManager);
      mRecyclerView.setAdapter(mAdapter);
  }
  
  // Other code
  
  private void goExerciseViewer(int position) {
       selectedCustomExercise = //number;
       selectedCustomRoutine = //number;
  }
  </code></pre>
  
  <p><strong>ExerciseViewerFragment.java</strong></p>
  
  <pre><code>private void saveChanges() { 
   customRoutineExercise.get(selectedCustomRoutine).get(selectedCustomExercise).setSetNumber(Integer.parseInt(editText1.getText().toString()));
   customRoutineExercise.get(selectedCustomRoutine).get(selectedCustomExercise).setRepNumber(Integer.parseInt(editText2.getText().toString()));
  }
  </code></pre>