title: RecyclerView Duplicating On Back Press in the Nested Recycler View
body: <p><strong>I create a nested recyclerView in my android project but when i am in the 2nd recyclerview and press back button in order to hide the keyboard. The Item of 2nd group automatically gets added at the end of 1st group.</strong></p>
  <p><img src="https://i.stack.imgur.com/uHWuE.jpg" alt="When Back button is not pressed" /></p>
  <p><img src="https://i.stack.imgur.com/7pQvd.jpg" alt="When back button is pressed Coca-Cola 330nl CAM 24 is duplicated in group 2000ml" /></p>
  <p><strong>Adapter for first Recycler View..</strong></p>
  <pre><code>import android.content.Context;
  import android.database.Cursor;
  import android.database.sqlite.SQLiteDatabase;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.EditText;
  import android.widget.LinearLayout;
  import android.widget.TextView;
  
  import androidx.annotation.NonNull;
  import androidx.cardview.widget.CardView;
  import androidx.recyclerview.widget.LinearLayoutManager;
  import androidx.recyclerview.widget.RecyclerView;
  
  import com.example.hrisv001.OutletOrdersSKUWiseActivity;
  import com.example.hrisv001.R;
  import com.example.hrisv001.api.OutletList;
  import com.example.hrisv001.api.SKUList;
  import com.example.hrisv001.api.SKU_Brands_List;
  import com.example.hrisv001.utils.SqlLiteHelper;
  
  import java.util.ArrayList;
  import java.util.List;
  
  public class SKUListAdapter extends RecyclerView.Adapter&lt;SKUListAdapter.HolderView&gt;{
  
      private List&lt;SKUList&gt; skulist;
      private List&lt;SKU_Brands_List&gt; sku_brands_lists=new ArrayList&lt;&gt;();
      Item_List_Adapter adapter;
      private Context context;
      public static SqlLiteHelper sqlLiteHelper;
  
  
  
      public SKUListAdapter(List&lt;SKUList&gt; skulist,Context context)
      {
          this.skulist=skulist;
          this.context=context;
          setHasStableIds(true);
      }
  
      @NonNull
      @Override
      public SKUListAdapter.HolderView onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
          View layout= LayoutInflater.from(parent.getContext()).inflate(R.layout.sku_wise_list_style,parent,false);
          context=parent.getContext();
          return new HolderView(layout);
      }
  
      @Override
      public void onBindViewHolder(@NonNull final SKUListAdapter.HolderView holder, final int position) {
          holder.txt_sku_name.setText(skulist.get(position).getSKUName());
          final RecyclerView list_itemname_sku=holder.list_itemname;
          final LinearLayout ll_itemlist=holder.ll_skuname;
          sqlLiteHelper=new SqlLiteHelper(context,&quot;SLMG_EMS.sqlite&quot;,null,1);
          final SQLiteDatabase databaseabplhee=sqlLiteHelper.getReadableDatabase();
  
          holder.cview_step1.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
  
                  for (int i=0;i&lt;skulist.size();i++)
                  {
                      if (i!=position)
                      {
                          ll_itemlist.setVisibility(View.GONE);
                      }
  
                  }
  
  
                  if (skulist.get(position).getExpanded() == null || skulist.get(position).getExpanded() == false) {
                      if (skulist.get(position).getValueAdded() == null || skulist.get(position).getValueAdded() == false) {
                          sku_brands_lists.clear();
                          String query = &quot;SELECT DISTINCT(ITEMID) AS ITEMIDD,ITEMNAME,MRPCOST FROM TB_SKU_WISE_ITEMS WHERE PACKSIZE='&quot; + skulist.get(position).getSKUName().trim() + &quot;'&quot;;
                          Cursor cursor = databaseabplhee.rawQuery(query, null);
                          cursor.moveToFirst();
  
                          while (!cursor.isAfterLast()) {
  
                              sku_brands_lists.add(new SKU_Brands_List(cursor.getString(cursor.getColumnIndex(&quot;ITEMIDD&quot;)), cursor.getString(cursor.getColumnIndex(&quot;ITEMNAME&quot;)), cursor.getString(cursor.getColumnIndex(&quot;MRPCOST&quot;)), 0.0));
                              cursor.moveToNext();
                          }
  
                          LinearLayoutManager linearLayoutManager = new LinearLayoutManager(
                                  list_itemname_sku.getContext(),
                                  LinearLayoutManager.VERTICAL,
                                  false
                          );
                          skulist.get(position).setValueAdded(true);
                          list_itemname_sku.setHasFixedSize(true);
                          list_itemname_sku.setLayoutManager(linearLayoutManager);
                          adapter = new Item_List_Adapter(sku_brands_lists, context);
                          list_itemname_sku.setAdapter(adapter);
                          ll_itemlist.setVisibility(View.VISIBLE);
                          skulist.get(position).setValueAdded(true);
  
                      } else {
                          ll_itemlist.setVisibility(View.VISIBLE);
                      }
                      skulist.get(position).setExpanded(true);
                  } else {
                      if (skulist.get(position).getValueAdded() == true) {
                          ll_itemlist.setVisibility(View.GONE);
                          skulist.get(position).setExpanded(false);
                      }
                  }
              }
  
  
  
          });
      }
  
  
      @Override
      public long getItemId(int position) {
          return position;
      }
  
      @Override
      public int getItemViewType(int position) {
          return position;
      }
  
      @Override
      public int getItemCount() {
          return skulist.size();
      }
  
      class HolderView extends RecyclerView.ViewHolder{
  
          TextView txt_sku_name;
          LinearLayout ll_skuname;
          RecyclerView list_itemname;
          CardView cview_step1;
  
          HolderView(View itemView)
          {
              super(itemView);
              cview_step1=itemView.findViewById(R.id.cview_step1);
              txt_sku_name=itemView.findViewById(R.id.txt_sku_name);
              ll_skuname=itemView.findViewById(R.id.ll_skuname);
              list_itemname=itemView.findViewById(R.id.list_itemname);
  
          }
  
      }
  }
  </code></pre>
  <p><strong>Adapter for first Recycler View..</strong></p>
  <pre><code>import android.content.Context;
  import android.content.SharedPreferences;
  import android.database.sqlite.SQLiteDatabase;
  import android.text.Editable;
  import android.text.TextWatcher;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.EditText;
  import android.widget.LinearLayout;
  import android.widget.TextView;
  
  import androidx.annotation.NonNull;
  import androidx.recyclerview.widget.RecyclerView;
  
  import com.example.hrisv001.ItemOpeningClosingActivity;
  import com.example.hrisv001.OutletOrdersSKUWiseActivity;
  import com.example.hrisv001.R;
  import com.example.hrisv001.api.SKUList;
  import com.example.hrisv001.api.SKU_Brands_List;
  import com.example.hrisv001.utils.AppConstants;
  import com.example.hrisv001.utils.SqlLiteHelper;
  
  import java.util.List;
  
  public class Item_List_Adapter extends RecyclerView.Adapter&lt;Item_List_Adapter.HolderView&gt; {
  
      List&lt;SKU_Brands_List&gt; sku_brands_lists;
      private Context context;
      public static SqlLiteHelper sqlLiteHelper;
      SharedPreferences sharedpreferences;
      String empid;
  
  
  
      public Item_List_Adapter(List&lt;SKU_Brands_List&gt; sku_brands_lists,Context context)
      {
          this.sku_brands_lists=sku_brands_lists;
          this.context=context;
          setHasStableIds(true);
      }
  
  
      @NonNull
      @Override
      public Item_List_Adapter.HolderView onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
  
          View layout= LayoutInflater.from(parent.getContext()).inflate(R.layout.brand_wise_list_style,parent,false);
          return new HolderView(layout);
  
      }
  
      @Override
      public void onBindViewHolder(@NonNull final Item_List_Adapter.HolderView holder, final int position) {
              holder.tv_itemid.setText(sku_brands_lists.get(position).getITEMID());
              holder.tv_brand_name.setText(sku_brands_lists.get(position).getITEMNAME());
               holder.tv_brand_rate.setText(sku_brands_lists.get(position).getMRPCost());
              final EditText itemqty_qty=holder.et_itm_quantityy;
  
          holder.et_itm_quantityy.addTextChangedListener(new TextWatcher() {
              @Override
              public void beforeTextChanged(CharSequence s, int start, int count, int after) {
  
              }
  
              @Override
              public void onTextChanged(CharSequence s, int start, int before, int count) {
  
              }
  
              @Override
              public void afterTextChanged(Editable s) {
                  OutletOrdersSKUWiseActivity itmop;
                  itmop = new OutletOrdersSKUWiseActivity();
                  itmop.deleteNinsertItemToTable(holder.tv_itemid.getText().toString(),holder.tv_brand_rate.getText().toString(),itemqty_qty.getText().toString(),holder.tv_brand_name.getText().toString());
  
  
  
              /*
  
                  sqlLiteHelper.DeleteLikeFromItemQtyList(holder.tv_itemid.getText().toString());
                  try {
                      sqlLiteHelper.insertSKUWiseItemQtyList(holder.tv_itemid.getText().toString(),Double.parseDouble(holder.tv_brand_rate.getText().toString()),Double.parseDouble(itemqty_qty.getText().toString()));
                  }
                  catch (Exception e){
                      e.printStackTrace();
                  }
  */
                 /* double itemqtyy=0;
                  if (itemqty_qty.getText().toString().trim().equals(null)||itemqty_qty.getText().toString().trim().equals(&quot;&quot;))
                  {
                      itemqtyy=0;
                  }
                  else
                  {
                      itemqtyy=Double.parseDouble(itemqty_qty.getText().toString());
                  }
                  sku_brands_lists.get(position).setQty(itemqtyy);*/
              }
          });
      }
  
  
      @Override
      public long getItemId(int position) {
          return position;
      }
  
      @Override
      public int getItemViewType(int position) {
          return position;
      }
  
      @Override
      public int getItemCount() {
          return sku_brands_lists.size();
      }
  
  
  
      class HolderView extends RecyclerView.ViewHolder{
  
          TextView tv_brand_name,tv_itemid,tv_brand_rate;
          EditText et_itm_quantityy;
  
          HolderView(View itemView)
          {
              super(itemView);
              tv_brand_name=itemView.findViewById(R.id.tv_brand_name);
              tv_itemid=itemView.findViewById(R.id.tv_itemid);
              tv_brand_rate=itemView.findViewById(R.id.tv_brand_rate);
              et_itm_quantityy=itemView.findViewById(R.id.et_itm_quantityy_itemwise);
          }
  
      }
  }
  </code></pre>