Andrew
Andrew

Reputation: 2157

Don't have access from activity to adapter method recyclerview

I found this example of adding swipe delete at recyclerview. But I can't see method of removing items at recyclerview adapter:

public void removeItem(int position) {
        data.remove(position);
        notifyItemRemoved(position);
    }

I decided that I have to add static but I didn't help. Maybe someone know how to solve this problem?

Upvotes: 1

Views: 140

Answers (2)

Elmira Frhn
Elmira Frhn

Reputation: 320

This is not your custom adapter:

 adapter = new ListAdapter(messageArrayList, getActivity(), type);

I guess you are using ListAdapter Class instead of your custom adapter. Could change (refactor) your ListAdapter class using another name like customAdapter for example?

Upvotes: 4

S-Sh
S-Sh

Reputation: 3873

The removeItem(int position) is method of adapter, not activity, so try mAdapter.removeItem(..) inside Activity code

Upvotes: 2

Related Questions