There is a fragment in which there is a request to the database, then the data is transferred to RecyclerView to form a list. Clicking on the list item opens the activity, there is a delete button. By tapu on the button there is a request to the database for deletion and the activity is closed through the finish.

In the onResume() method, the list item is caught, which was also deleted via mAdapter.notifyItemRemoved(deleteItem); There is an animated hiding of this item from the list.

Everything is fine, but at the bottom of the screen there is a duplicate of the last visible item on the list. After searching, I came across several examples of the same solution - adding my method to the adapter to update the list and access this method. One of these examples is described in this answer from pavlofff

But for some reason, when I refer to the adapter method in onResume() or onCreateView() the method name itself is highlighted in red (as if there is no method), and in the adapter itself, the method name is highlighted in gray (as if the method is not used) and of course nothing works.

screen

  • Most likely the variable type of the adapter is incorrect. Show the announcement thereof and the name of the adapter class - YuriySPb
  • @Yuriy SPb, I don’t know if it will be correct to duplicate information from one question to another. Just in case, I will not risk it. I placed the fragment and adapter code in the previous question on a similar issue. Only now this code is supplemented with onResume and the method itself in the adapter. Look here please. - Gamlet
  • In this question, there is no indication of the type of the declared variable - Yuriy SPb
  • @YuriSPb, I apologize. In terms of not strong. What exactly and where to register? - Gamlet
  • one
    You have a variable in the snippet named myAdapter . If you cannot call the method described in the adapter, then, apparently, its type is not defined as RecyclerAdapterTab1 , but something like RecyclerView.Adapter . Those. RecyclerView.Adapter mAdapter . If so, you just need to replace the type of the variable with the type of your adapter, i.e. on RecyclerAdapterTab1 . Well, or to him when calling the method. - Yuriy SPb

1 answer 1

In this case, the class method RecyclerAdapterTab1 not visible to the compiler, because the variable is declared with the type RecyclerView.Adapter , but it does not have such a method.

So it is necessary or change the type of variable

 //RecyclerView.Adapter mAdapter; RecyclerAdapterTab1 mAdapter; 

or speak to it when calling the method

 RecyclerView.Adapter mAdapter; ... ((RecyclerAdapterTab1)mAdapter).dataChanged(data);