title: How to update RecyclerView Adapter Data while adding new item in List
body: <p>I am working on a functionality in which I have added FooterView to my RecyclerView. I am adding a new item in the list by clicking on "+" icon in FooterView. The item successfully added in the ArrayList from fragment and data has been added to local database but a new list item have not added in the list as adapter is not able to update at same time. When I go to another screen then come back to this screen then I am able to see the item. I tried to do but not able to do so.</p>
  
  <p>Code for Adapter : `public class RecyclerViewAdapter extends RecyclerView.Adapter {</p>
  
  <pre><code>private static final int TYPE_HEADER = 0;
  private static final int TYPE_FOOTER = 1;
  private static final int TYPE_ITEM = 2;
  
  
  private Activity activity;
  
  ArrayList&lt;ModelUnrecognisedCode&gt; modelUnrecognisedCodesArrayList;
  FinalizePreOrde finalizePreOrderFragment;
  ModelUnrecognisedCode modelUnrecognisedCode;
  
  public RecyclerViewAdapter(Activity activity, ArrayList&lt;ModelUnrecognisedCode&gt; modelUnrecognisedCodesArrayList, FinalizePreOrde finalizePreOrderFragment) {
      this.activity = activity;
      this.modelUnrecognisedCodesArrayList = modelUnrecognisedCodesArrayList;
      this.finalizePreOrderFragment = finalizePreOrderFragment;
  }
  
  @Override
  public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
      if (viewType == TYPE_ITEM) {
          //Inflating recycle view item layout
          View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_list_unrecognised_item, parent, false);
          return new ItemViewHolder(itemView);
      } else if (viewType == TYPE_FOOTER) {
          //Inflating footer view
          View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_footer_view, parent, false);
          return new FooterViewHolder(itemView);
      } else return null;
  }
  
  @Override
  public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
  
  
      if (holder instanceof FooterViewHolder) {
          final FooterViewHolder footerHolder = (FooterViewHolder) holder;
  
          footerHolder.imgAddMore.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
  
                  finalizePreOrderFragment.addView(footerHolder.etCode.getText().toString(), position);
  
              }
          });
  
  
      } else if (holder instanceof ItemViewHolder) {
          final ItemViewHolder itemViewHolder = (ItemViewHolder) holder;
          modelUnrecognisedCode = modelUnrecognisedCodesArrayList.get(position);
          itemViewHolder.etCode.setText(modelUnrecognisedCode.getUnrecognised_code());
  
  
      }
  }
  
  @Override
  public int getItemViewType(int position) {
      if (position == modelUnrecognisedCodesArrayList.size()) {
          return TYPE_FOOTER;
      }
      return TYPE_ITEM;
  }
  
  @Override
  public int getItemCount() {
      return modelUnrecognisedCodesArrayList.size() + 1;
  }
  </code></pre>
  
  <p>` </p>
  
  <p>in BindView Holder inside footer section I have added code to click on "+" icon and add new item in the list</p>
  
  <pre><code>footerHolder.imgAddMore.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
  
                  finalizePreOrderFragment.addView(footerHolder.etCode.getText().toString(), position);
  
              }
          });
  </code></pre>
  
  <p>And now my Fragment code to add new </p>
  
  <pre><code> public void addView(String code, int position) {
      ModelUnrecognisedCode modelUnrecognisedCode = new ModelUnrecognisedCode();
      modelUnrecognisedCode.setUnrecognised_code(code);
      modelUnrecognisedCode.setUnrecognised_comment("comment");
      modelUnrecognisedCode.setShop_id("1");
      modelUnrecognisedCode.setShop_name_fr("fr");
      modelUnrecognisedCode.setShop_name_nl("nl");
      databaseHelper.addUnrecognisedCode(modelUnrecognisedCode);
      modelUnrecognisedCodesArrayList = databaseHelper.getUnrecognisedCode();
  
      adapterUnrecognisedCode.notifyItemInserted(position);
      adapterUnrecognisedCode.notifyItemRangeChanged(position, modelUnrecognisedCodesArrayList.size());
      adapterUnrecognisedCode.notifyDataSetChanged();
  
      Log.e("TAG", "unrecognised code: " + modelUnrecognisedCodesArrayList.size());
  }
  </code></pre>
  
  <p>I am able to add the item in the ArrayList but adapter not updated when I press back and then come back again then I am able to see the item. Please help</p>