After deleting the data from the database, you must update the ListView to display the changes. But the Studio says that the requery() is deprecated . What function can be used together? Here they say that you need to re-call the cursor. But I did not understand how to do it.

UPD: Copied the first code and re-called the cursor with this code did not help.

 cursor = mSqLiteDatabase.rawQuery("select * from "+ DatabaseHelper.DATABASE_TABLE, null); 

    2 answers 2

    Solved the problem in this way. First re-called the cursor by the code by which it was created.

     cursor = mSqLiteDatabase.rawQuery("select * from "+ DatabaseHelper.DATABASE_TABLE, null); 

    Then I used the SimpleCursorAdapter functions:

     userAdapter.swapCursor(cursor); userAdapter.notifyDataSetChanged(); 

    It works as it should. First we call the cursor again, then use the methods listed above. All together looks like this:

     cursor = mSqLiteDatabase.rawQuery("select * from "+ DatabaseHelper.DATABASE_TABLE, null); userAdapter.swapCursor(cursor); userAdapter.notifyDataSetChanged(); 

    Ps1. In solving the problem, this helped

    PS2. If you do not have a SimpleCursorAdapter you need to create it with something like this:

     userAdapter = new SimpleCursorAdapter(this, R.layout.siyahi_obyekti, cursor, headers, new int[]{R.id.textView5, R.id.textView6,R.id.textView7}, 0); siyahi.setAdapter(userAdapter); 

      You did not understand the main goal of Google (Android) to change the policy to cursors. The idea is to bring the process of loading the cursor from the main thread into the background, which would not slow down the application for the user. YES, you have used the command

       swapCursor(cursor); 

      but it’s like a birch traction Japanese car. This command is intended to update the data in the main stream on the ALREADY loaded in the background cursor. Changes to the work with the cursor are a big topic, and several teams cannot get rid of it. I advise you to study CursorLoders, or at least asynchronous tasks, this is the first. And the second is Content Providers, if you need to share info with other applications. Although fans mold them everywhere.