Answer the question
In order to leave comments, you need to log in
How to update a reference inside a nested class definition?
A bit strange wording of the question, but I couldn't think of a better one. There is a code (simplified to see the main thing):
@Override
protected void onCreate(){
Callback call = new Callback((answer)->{
MyAdapter adapter = new MyAdapter(answer);
ItemTouchHelper.SimpleCallback itemTouchHelperCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT) {
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
adapter.deleteAt(viewHolder.getAdapterPosition());
}
};
btn.setOnClickListener(()->{
API.response().enqueue(call);
});
API.response().enqueue(call);
}
Answer the question
In order to leave comments, you need to log in
The problem turned out to be outside the provided code, namely in the line just below:
new ItemTouchHelper(itemTouchHelperCallback).attachToRecyclerView(recyclerView);
if(touchHelper != null)
touchHelper.attachToRecyclerView(null);
touchHelper = new ItemTouchHelper(itemTouchHelperCallback);
touchHelper.attachToRecyclerView(recyclerView);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question