Created a list using Recyclerview. There was a problem. After writing data to the database, a new item appears only after restarting the application. Please explain how to make this list updated.

using this method I get data from the database

public List<CategoryList> getTodayItems() throws SQLException, ParseException { open(); categoriesList = new ArrayList<>(); String strSQL = "select category_name, category_photo, operat_date, operat_sum\n" + "from source, income, operations\n" + "where source._id = id_source and operations._id = id_of_transaction and operat_date LIKE '" + getCurrentDate() + "%'" + " order by operat_date DESC"; Cursor c = database.rawQuery(strSQL, null); if (c.moveToFirst()) { // определяем номера столбцов по имени в выборке int nameIndex = c.getColumnIndex(dbHelper.COLUMN_NAME); int photoIndex = c.getColumnIndex(dbHelper.COLUMN_PHOTO); int dateIndex = c.getColumnIndex(dbHelper.COLUMN_OPERAT_DATE); int sumIndex = c.getColumnIndex(dbHelper.COLUMN_OPERAT_SUM); do { categoriesList.add(new CategoryList(c.getString(nameIndex), c.getInt(photoIndex), "Мои деньги", String.valueOf(c.getInt(sumIndex)), String.valueOf(makeDate(String.valueOf(c.getLong(dateIndex)))))); // получаем значения по номерам столбцов Log.d(LOG_TAG, "NAME = " + c.getString(nameIndex) + " PHOTO = " + c.getInt(photoIndex) + " DATE = " + c.getInt(dateIndex) + " SUM = " + c.getInt(sumIndex)); } while (c.moveToNext()); } close(); return categoriesList; } 

then I do this:

  categoriesListsToday = myDb.getTodayItems(); final CategoryListAdapter adapterList = new CategoryListAdapter(categoriesListsToday, new CategoryListAdapter.OnItemClickListener() { @Override public void onItemClick(CategoryList category) { // } }); rvList.setAdapter(adapterList); 
  • Adapter.notifyDataSetChange ()? - Djangorussia
  • @jangorussia, maybe I didn’t understand how to do it, for example, I add new information, add and need to exit go to the application to see the new added item, or go to another activation and re-enter the activation with Recyclerview, and I need to add immediately update your Recyclerview and see the new item - java
  • After updating the database, you need to add new elements to the list using list.addAll (elements), and then call adapter.notifyDataSetChanged () on the adapter, as jangorussia wrote above. - Android Android
  • You have a line of code: myRecyclerView.setAdapter (myAdapter) ;. In this line there is an instance of myAdapter, and in turn it has a method notifiDateSetChange () it inherits from abstract ancestors. If you update the adapter, which is a wrapper for access to the data set, then you and the recuperator are redrawn, without recreating the activation with the recuperator - Djangorussia
  • @AndroidAndroid, if I understood correctly, then when I click on the add button, am I doing something like this? myDb.add(category, textView_sum, true); categoriesListsToday.clear(); categoriesListsToday.addAll(categoriesListsToday); adapterList.notifyDataSetChanged(); , if yes, then why it didn't help - java

0