title: Update Parent Adapter in Nested Adapters?
body: <p>I have nested adapters for two RecyclerViews kind of like so:<br />
  Parent Adapter:</p>
  <pre><code>public class ParentAdapter extends RecyclerView.Adapter&lt;RecyclerView.ViewHolder&gt; {
      public static ArrayList&lt;ParentItem&gt; parentItemList;
  
      private RecyclerView.RecycledViewPool viewPool = new RecyclerView.RecycledViewPool();
  
      private com.example.todotestapp.ChildAdapter childAdapter;
  
      public ParentAdapter(ArrayList&lt;ParentItem&gt; parentItemList) {
          this.parentItemList = parentItemList;
      }
  
      public class ParentViewHolder extends RecyclerView.ViewHolder {
  
          private RecyclerView childRecyclerView;
          public ParentViewHolder(final View parentView) {
              super(parentView);
  
              childRecyclerView = parentView.findViewById(R.id.child_recyclerview);
          }
      }
  
      @Override
      public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          Context context = parent.getContext();
          LayoutInflater inflater = LayoutInflater.from(context);
          View parentView = inflater.inflate(R.layout.parent_layout, parent, false);
          return new ParentViewHolder(parentView);
      }
  
      @Override
      public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
  
          final ParentItem someParentItem = parentItemList.get(position);
  
          ArrayList&lt;ChildItem&gt; childItemList = someParentItem.getChildItemList();
          RecyclerView childRecyclerView = ((ParentViewHolder) holder).childRecyclerView;
          LinearLayoutManager layoutManager = new LinearLayoutManager(childRecyclerView.getContext());
          layoutManager.setInitialPrefetchItemCount(childItemList.size());
          childAdapter = new com.example.todotestapp.ChildAdapter(childItemList);
          childRecyclerView.setLayoutManager(layoutManager);
          childRecyclerView.setAdapter(childAdapter);
          childRecyclerView.setRecycledViewPool(viewPool);
  
      }
  
      @Override
      public int getItemCount() {return parentItemList.size(); }
  }
  
  </code></pre>
  <p>Child Adapter:</p>
  <pre><code>public class ChildAdapter extends RecyclerView.Adapter&lt;RecyclerView.ViewHolder&gt; {
      private ArrayList&lt;ChildItem&gt; childItemList;
  
      public ChildAdapter(ArrayList&lt;ChildItem&gt; childItemList) {
          this.childItemList = childItemList;
      }
  
      public class ChildViewHolder extends RecyclerView.ViewHolder {
          CheckBox childCheckBox;
  
          public ChildViewHolder(final View childView) {
              super(childView);
  
              childCheckBox = childView.findViewById(R.id.child_checkbox);
              childCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                  @Override
                  public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                      ChildItem checkedChildItem = childItemList.get(getAdapterPosition());
  
                      ParentItem parentItemOfCheckedChildItem = checkedChildItem.getParentItem();
                      int parentAdapterPos = ParentAdapter.parentItemList.indexOf(parentItemOfCheckedChildItem);
                      int mainPos = MainActivity.mainParentItemList.indexOf(parentItemOfCheckedChildItem);
                      ArrayList&lt;ChildItem&gt; aChildItemList = parentItemOfCheckedChildItem.getChildItemList();
                      aChildItemList.remove(checkedChildItem);
                      childItemList.remove(checkedChildItem);
                      parentItemOfCheckedChildItem.setChildItemList(aChildItemList);
                      ParentAdapter.parentItemList.set(parentAdapterPos, parentItemOfCheckedChildItem);
                      MainActivity.mainParentItemList.set(mainPos, parentItemOfCheckedChildItem);
  
                      MainActivity.mainChildItemList.remove(checkedChildItem);
                      checkedChildItem.setIsChecked(true);
                      MainActivity.mainChildItemList.add(checkedChildItem);
  
                      ParentItem checkedParentItem = ParentAdapter.parentItemList.get(ParentAdapter.parentItemList.size() - 1);
                      checkedParentItem.addToChildItemList(checkedChildItem);
                      ParentAdapter.parentItemList.set(ParentAdapter.parentItemList.size() - 1, checkedParentItem);
  
                      notifyDataSetChanged();
                  }
              });
          }
      }
      @NonNull
      @Override
      public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
          Context context = parent.getContext();
          LayoutInflater inflater = LayoutInflater.from(context);
          View childView = inflater.inflate(R.layout.child_layout, parent, false);
          return new ChildViewHolder(childView);
      }
      @Override
      public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
          final ChildItem aChildItem = childItemList.get(position);
      }
  
      @Override
      public int getItemCount() {return childItemList.size();}
  }
  </code></pre>
  <p>I know the ChildAdapter is pretty messy, but I'm having trouble handling the data. I'd like to delete the checkedChildItem from its current ParentItem, add it to a new ParentItem, and then have the data refreshed. My current code does the first two steps (deletes the ChildItem from the original ParentItem's childItemList and adds it to the new ParentItem's) but only displays the data after the activity is refreshed.<br />
  I've tried passing the data to the ParentAdapter in a &quot;updateDataAfterChecked&quot; method, but I still can't update it since the ChildItemViewHolder is a static context and notifyDataSetChanged() is not, so I can't seem to find a way to update the ParentAdapter without going to a different activity and back again. Any suggestions?<br />
  ------------------------------------EDIT----------------------------------------<br />
  I was able to access .notifyDataSetChanged() by utilizing LiveData for the ParentItemList, but the ChildItem still doesn't show up in the second ParentItem until the page is refreshed (if I call finish() then startActivity(getIntent()), everything works as it's supposed to, except this causes a jarring effect that I dislike). Any suggestions to help fix this issue? Thanks.<br />
  ------------------------------------EDIT----------------------------------------<br />
  What I'm aiming for is something like what the Google Tasks app (android) does--if you check off an item, it gets removed from its date and added to &quot;Completed&quot; in real time; I don't know if this information helps with answers at all, but I thought it'd be worth mentioning.</p>