title: RecyclerView does not update after add data
body: <p>I'm migrating from ListView to RecyclerView, but after entering some data in SQLite, my list is not updated using notifyDataSetChanged (); so I always have to call the setAdapter () method;</p>
  
  <p>I have simplified my code to post here. can anyone help me fix the notifyDataSetChanged (); to work in my code please?</p>
  
  <p><strong>RecyclerViewAdapter</strong></p>
  
  <pre><code>public class RecyclerViewAdapter extends RecyclerView.Adapter&lt;ViewHolder&gt; {
  
  private List&lt;Model&gt; model;
  private Context context;
  
  public RecyclerViewAdapter(Context context, List&lt;Model&gt; model) {
      this.context = context;
      this.model = new ArrayList&lt;&gt;(model);
  }
  
  @Override
  public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
      View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.custom_layout, parent, false);
      return new ViewHolder(context, view, model);
  }
  
  @Override
  public void onBindViewHolder(ViewHolder holder, int position) {
      final Model model = model.get(position);
      holder.bind(model);
  }
  
  @Override
  public int getItemCount() {
      return model.size();
  } }
  </code></pre>
  
  <p><strong>ViewHolder</strong></p>
  
  <pre><code>public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
  
  private List&lt;Model&gt; model = new ArrayList&lt;&gt;();
  private Context context;
  
  private TextView textViewGroup;
  private TextView textViewName;
  
  public ViewHolder(Context context, View itemView, List&lt;Model&gt; model) {
      super(itemView);
  
      this.model = model;
      this.context = context;
  
      itemView.setOnClickListener(this);
  
      textViewGroup = (TextView) itemView.findViewById(R.id.textViewGroup);
      textViewName = (TextView) itemView.findViewById(R.id.textViewName);
  
  }
  
  public void bind(Model model) {
      textViewGroup.setText(model.getGroup());
      textViewName.setText(model.getName());
      }
  }
  
  @Override
  public void onClick(View view) {
      Model model = this.model.get(getAdapterPosition());
      Intent intent = new Intent(this.context, ShowGroup.class);
      intent.putExtra("DATA", model);
      intent.putExtra("POSITION", getAdapterPosition());
      ((Activity) this.context).startActivityForResult(intent, 7);
  
      Log.i("&gt;&gt;", "_IDHOLDER: " + model.getId());
      Log.i("&gt;&gt;", "_POSITION: " + getAdapterPosition());
      Log.i("&gt;&gt;", ".");
  } }
  </code></pre>
  
  <p><strong>Model</strong></p>
  
  <pre><code>public class Model implements Serializable {
  
  public static final String TABLE = "GROUP_NAME";
  public static final String ID = "_ID";
  public static final String GROUP = "GROUP";
  public static final String NAME = "NAME";
  
  private long id;
  private String group;
  private String name;
  
  public Model() {
      setId(0);
  }
  
  public long getId() {
      return id;
  }
  
  public void setId(long id) {
      this.id = id;
  }
  
  public String getGroup() {
      return group;
  }
  
  public void setGroup(String group) {
      this.group = group;
  }
  
  public String getName() {
      return name;
  }
  
  public void setName(String name) {
      this.name = name;
  } }
  </code></pre>
  
  <p><strong>Repository</strong></p>
  
  <pre><code>public class Repository {
  
  private SQLiteDatabase db;
  
  public Repository(SQLiteDatabase db) {
      this.db = db;
  }
  
  private ContentValues fillModelValues(Model model) {
      ContentValues values = new ContentValues();
      values.put(Model.GROUP, model.getGroup());
      values.put(Model.NAME, model.getName());
  
      return values;
  }
  
  public void insert(Model model) {
      ContentValues values = fillModelValues(model);
      db.insertOrThrow(Model.TABLE, null, values);
  }
  
  public List&lt;Model&gt; consDataBase(Context context) {
  
      List&lt;Model&gt; listModel = new ArrayList&lt;&gt;();
  
      Cursor cursor = db.query(Model.TABLE, null, null, null, null, null, null);
  
      if (cursor.getCount() &gt; 0) {
          cursor.moveToFirst();
  
          do {
              Model model = new Model();
              model.setId(cursor.getLong(cursor.getColumnIndex(Model.ID)));
              model.setGroup(cursor.getString(cursor.getColumnIndex(Model.GROUP)));
              model.setName(cursor.getString(cursor.getColumnIndex(Model.NAME)));
  
              listModel.add(model);
  
          } while (cursor.moveToNext());
      }
  
      cursor.close();
  
      return listModel;
  } }
  </code></pre>
  
  <p><strong>MainActivity</strong></p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
  private List&lt;Model&gt; listModel;
  private LinearLayoutManager layoutManager;
  private RecyclerView recyclerView;
  private RecyclerViewAdapter recyclerViewAdapter;
  
  private FloatingActionButton fab;
  
  private DataBase dataBase;
  private SQLiteDatabase db;
  private Repository repository;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      layoutManager = new LinearLayoutManager(this);
      recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
      recyclerView.setLayoutManager(layoutManager);
  
      fab = (FloatingActionButton) findViewById(R.id.fab);
      fab.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              startActivityForResult(new Intent(MainActivity.this, AddGroup.class), 4);
          }
      });
  
      try {
          dataBase = new DataBase(this);
          db = dataBase.getWritableDatabase();
          repository = new Repository(db);
  
          listModel = repository.consDataBase(context);
          recyclerViewAdapter = new RecyclerViewAdapter(context, listModel);
          recyclerView.setAdapter(recyclerViewAdapter);
          recyclerView.setHasFixedSize(true);
  
      } catch (SQLException e) {
  
      }
  }
  
  @Override
  protected void onDestroy() {
      super.onDestroy();
      if (db != null) {
          db.close();
      }
  }
  
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
  
      if (requestCode == 4) {
  
          listModel = repository.consDataBase(context);
          recyclerViewAdapter = new RecyclerViewAdapter(context, listModel);
          recyclerView.setAdapter(recyclerViewAdapter);       
      }
  } }
  </code></pre>
  
  <p><strong>AddGroup</strong></p>
  
  <pre><code>public class AddGroup extends AppCompatActivity {
  
  private EditText editTextGroup;
  private EditText editTextName;
  
  private DataBase dataBase;
  private SQLiteDatabase db;
  private Repository repository;
  private Model model;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_add_group);
  
      editTextGroup = (EditText) findViewById(R.id.editTextGroup);
      editTextName = (EditText) findViewById(R.id.editTextName);
  
      try {
          dataBase = new DataBase(this);
          db = dataBase.getWritableDatabase();
          repository = new Repository(db);
          model = new Model();
  
      } catch (SQLException e) {
  
      }
  }
  
  private void saveModel() {
      try {
          model.setGroup(editTextGroup.getText().toString().trim());
          model.setName(editTextName.getText().toString().trim());
          if (model.getId() == 0) {
              repository.insert(model);
          }
  
      } catch (Exception e) {
  
      }
  }
  
  @Override
  protected void onDestroy() {
      super.onDestroy();
      if (db != null) {
          db.close();
      }
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      MenuInflater inflater = getMenuInflater();
      inflater.inflate(R.menu.menu_add_group, menu);
  
      return super.onCreateOptionsMenu(menu);
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      if (item.getItemId() == R.id.action_save) {
          saveModel();            
  
      }
      return super.onOptionsItemSelected(item);
  } }
  </code></pre>