title: Nested Recycler View, Child And Parent Remove Issue
body: <p>I have created a Nested recycle rview with parent and child both dynamic.Addition to both Parent and Child is working fine.Deletion from child is working fine.I want to remove parent view when all the child views for the same is removed.Confused about how could i implement the same.</p>
  <p>Here is the child Adapter</p>
  <pre><code>public class MyAdapter extends RecyclerView.Adapter&lt;MyAdapter.ViewHolder&gt; {
  
      private List&lt;ToDoModel&gt; values;
      private Context context;
      //private OnEditListener onEditListener;
      AlertDialog alertDialog;
  
      /*public MyAdapter(List&lt;ToDoModel&gt; context) {
          this.values = context;
          this.onEditListener = onEditListener;
      }*/
  
  
      public static class ViewHolder extends RecyclerView.ViewHolder {
  
          public TextView txtHeader;
          public TextView txtFooter;
          public ImageView mIcon;
          public View layout;
          public ImageView deleteItem;
          public CheckBox doneButton;
          public ImageView editItem;
  
          public ViewHolder(View v) {
              super(v);
              layout = v;
              txtHeader = (TextView) v.findViewById(R.id.firstLine);
              txtFooter = (TextView) v.findViewById(R.id.secondLine);
              mIcon = (ImageView) v.findViewById(R.id.icon);
              deleteItem = (ImageView) v.findViewById(R.id.deleteButton);
              doneButton = (CheckBox) v.findViewById(R.id.checkBox);
              editItem = (ImageView) v.findViewById(R.id.editButton);
          }
      }
  
      public void add(int position, ToDoModel item) {
          values.add(position, item);
          sort();
          notifyDataSetChanged();
          //notifyItemInserted(position);
      }
  
      public void replace(ToDoModel item)
      {
          int editPos;
          editPos = values.indexOf(item);
          values.set(editPos,item);
          sort();
          notifyDataSetChanged();
      }
  
      public void sort() {
          if ((int) values.size() &gt; 1) {
              Collections.sort(values);
          }
      }
  
      public void remove(int position) {
          values.remove(position);
          notifyDataSetChanged();
      }
  
      public MyAdapter(List&lt;ToDoModel&gt; myDataset) {
          values = myDataset;
      }
  
  
      @Override
      public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
                                                     int viewType) {
  
          LayoutInflater inflater = LayoutInflater.from(
                  parent.getContext());
          View v =
                  inflater.inflate(R.layout.todo_row_view, parent, false);
  
          ViewHolder vh = new ViewHolder(v);
          return vh;
      }
  
  
      @Override
      public void onBindViewHolder(ViewHolder holder, final int position) {
  
          final ToDoModel toDoModel = values.get(position);
  
          switch ((String) toDoModel.task) {
              case &quot;To Go&quot;:
                  holder.mIcon.setImageResource(R.drawable.ic_explore24px);
                  break;
              case &quot;To Get&quot;:
                  holder.mIcon.setImageResource(R.drawable.ic_shoppingbag24px);
                  break;
              case &quot;To Do&quot;:
                  holder.mIcon.setImageResource(R.drawable.ic_todo);
                  break;
              default:
                  break;
  
          }
  
          holder.txtHeader.setText(toDoModel.header);
          holder.txtFooter.setText(toDoModel.task + &quot; | &quot; + toDoModel.tod + &quot; | &quot; + toDoModel.footer);
  
          holder.doneButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
              @Override
              public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                  if (buttonView.isChecked()) {
                      //holder.mIcon.setImageResource(R.drawable.ic_check_circle24px);
                      Toast.makeText(buttonView.getContext(), &quot;Marked As Done&quot;, Toast.LENGTH_SHORT).show();
                  } else {
                      Toast.makeText(buttonView.getContext(), &quot;Marked As UnDone&quot;, Toast.LENGTH_SHORT).show();
                  }
              }
          });
  
  
          holder.deleteItem.setOnClickListener(new OnClickListener() {
              @Override
              public void onClick(View v) {
  
                  AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext());
                  View view = LayoutInflater.from(v.getContext()).inflate(R.layout.delete_promptdialog,null);
                  Button YesButton = (Button) view.findViewById(R.id.buttonYes);
                  Button NoButton = (Button) view.findViewById(R.id.buttonNo);
  
                  YesButton.setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View v) {
                          remove(position);
                          Toast.makeText(v.getContext(), &quot;List Item Removed&quot;, Toast.LENGTH_SHORT).show();
                          alertDialog.dismiss();
                      }
                  });
                  NoButton.setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View v) {
                          Toast.makeText(v.getContext(), &quot;Delete Canceled&quot;, Toast.LENGTH_SHORT).show();
                          alertDialog.dismiss();
                      }
                  });
  
                  builder.setView(view);
                  alertDialog=builder.create();
                  alertDialog.show();
                  /*remove(position);
                  Toast.makeText(v.getContext(), &quot;List Item Removed&quot;, Toast.LENGTH_SHORT).show();*/
              }
          });
  
  
         /* holder.editItem.setOnClickListener(new OnClickListener() {
              @Override
              public void onClick(View v) {
  
                  onEditListener.onEditClick(values.get(position));
                  //Toast.makeText(v.getContext(), &quot;List Edit&quot;, Toast.LENGTH_SHORT).show();
              }
          });*/
  
      }
  
     /*public interface OnEditListener {
  
          void onEditClick(ToDoModel currentData);
  
      }*/
  
  
      @Override
      public int getItemCount() {
          return values.size();
      }
  
  }
  </code></pre>
  <p>Here is the Parent Adapter</p>
  <pre><code>public class ParentAdapter extends RecyclerView.Adapter&lt;ParentAdapter.ParentViewHolder&gt; {
  
      private RecyclerView.RecycledViewPool viewPool = new RecyclerView.RecycledViewPool();
  
      public List&lt;TodoParent&gt; parentList;
      public TodoParent todayList;
      public static long todayEpochDate;
  
      public ParentAdapter(List&lt;TodoParent&gt; parentList, MainFragment mainFragment) {
  
          this.parentList = parentList;
  
      }
  
      public void add(int position, TodoParent item) {
          parentList.add(position, item);
          sort();
          notifyDataSetChanged();
          //notifyItemInserted(position);
      }
      public void sort() {
          if ((int) parentList.size() &gt; 1) {
              Collections.sort(parentList);
              //if(!(todayList.ParentTitle.isEmpty())) Collections.swap(parentList, parentList.indexOf(todayList), 0);
          }
  
         /* if ( todayList )
          {
              System.out.println(&quot;Entering Swap&quot;);
              setToday(todayList);
          }*/
      }
  
      public void setToday(TodoParent item) {
          int todayPos;
          todayPos = parentList.indexOf(item);
          parentList.remove(todayPos);
          notifyDataSetChanged();
          parentList.add(0,item);
          notifyDataSetChanged();
      }
  
      @NonNull
      @Override
      public ParentAdapter.ParentViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
  
          View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.todo_parent_view,parent,false);
          ParentViewHolder vh =  new ParentViewHolder(view);
          return vh;
      }
  
      @RequiresApi(api = Build.VERSION_CODES.N)
      @Override
      public void onBindViewHolder(@NonNull ParentViewHolder holder, int position) {
  
          TodoParent todoParent = parentList.get(position);
          todoParent.ParentId = position;
  
          Calendar mCal;
          mCal = Calendar.getInstance();
          int mDay = mCal.get(Calendar.DAY_OF_MONTH);
          int mMonth = mCal.get(Calendar.MONTH);
          int mYear = mCal.get(Calendar.YEAR);
          
          String dateString = mDay +&quot;/&quot;+ (mMonth+1) +&quot;/&quot; + mYear;
          try {
              todayEpochDate = new SimpleDateFormat(&quot;dd/MM/yyyy&quot;).parse(dateString).getTime()/1000;
          } catch (ParseException e) {
              e.printStackTrace();
          }
  
          if((long)todayEpochDate == (long)todoParent.EpochTime)
          {
              holder.mTitle.setText(&quot;Today&quot;);
              todayList = todoParent;
              System.out.println(&quot;todayE:&quot;+todayEpochDate);
              System.out.println(&quot;SelectedE:&quot;+todoParent.EpochTime);
          }
          else
          {
              holder.mTitle.setText(todoParent.ParentTitle);
              System.out.println(&quot;today:&quot;+todayEpochDate);
              System.out.println(&quot;Selected:&quot;+todoParent.EpochTime);
          }
  
          LinearLayoutManager layoutManager = new LinearLayoutManager(holder.childView.getContext(),
                  LinearLayoutManager.VERTICAL,false);
          layoutManager.setInitialPrefetchItemCount(todoParent.mChildList.size());
  
          holder.childView.setLayoutManager(layoutManager);
  
          MyAdapter myAdapter = new MyAdapter(todoParent.mChildList);
  
          holder.childView.setAdapter(myAdapter);
          holder.childView.setRecycledViewPool(viewPool);
  
      }
  
      @Override
      public int getItemCount() {
          return parentList.size();
      }
  
      public class ParentViewHolder extends RecyclerView.ViewHolder {
  
          public TextView mTitle;
          public RecyclerView childView;
  
          public ParentViewHolder(@NonNull View itemView) {
              super(itemView);
              mTitle = itemView.findViewById(R.id.mParentTitle);
              childView = itemView.findViewById(R.id.mChildView);
          }
      }
  }
  </code></pre>
  <p>remove for child is working fine. How to remove Parent here when there are no more child views?</p>