Cannot resolve adapter method when using DifUtil

January 12, 2019, at 7:00 PM

I want to update my RecyclerView using DifUtil to prevent duplicates. This is how my User class look like:

public class User {
    private String mUserId;
    private Uri mImageUrl;

    public User(String userId, String imageUrl) {
        mUserId = userId;
        mImageUrl = Uri.parse(imageUrl);

    public String getUserId() {
        return mUserId;
    public Uri getImageUrl() {
        return mImageUrl;

This is how I set data dynamically (I keep getting new Json arrays from the server containing user id's to be displayed, then I set the user image from Firebase storage):

    public void onResponse(JSONArray response) { // the JSON ARRAY response of user ids ["uid1", "uid334", "uid1123"]
        myDataset.clear(); // clear dataset to prevent duplicates
        for (int i = 0; i < response.length(); i++) {
            try {
                String userKey = response.get(i).toString(); // the currently iterated user id
                final DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
                DatabaseReference userKeyRef = rootRef.child("users").child(userKey); // reference to currently iterated user
                ValueEventListener listener = new ValueEventListener() {
                public void onDataChange(DataSnapshot dataSnapshot) {
                    myDataset.add(new User(dataSnapshot.getKey(), dataSnapshot.child("imageUrl").getValue().toString())); //add new user: id and image url
                    mAdapter.updateList(mDataset); // cannot resolve this method, why?
               public void onCancelled(@NonNull DatabaseError databaseError) {
               Log.d(TAG, databaseError.getMessage());
          catch (JSONException e) { Log.d(TAG, "message " + e); }

This is how my DifUtil class looks like:

public class MyDiffUtilCallBack extends DiffUtil.Callback{
    ArrayList<User> oldUsers;
    ArrayList<User> newUsers;
    public MyDiffUtilCallBack(ArrayList<User> newUsers, ArrayList<User> oldUsers) {
        this.newUsers = newUsers;
        this.oldUsers = oldUsers;
    public int getOldListSize() {
        return oldUsers.size();
    public int getNewListSize() {
        return newUsers.size();
    public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
        return oldUsers.get(oldItemPosition).getUserId() == newUsers.get(newItemPosition).getUserId();
    public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
        return oldUsers.get(oldItemPosition).equals(newUsers.get(newItemPosition));
    public Object getChangePayload(int oldItemPosition, int newItemPosition) {
        //you can return particular field for changed item.
        return super.getChangePayload(oldItemPosition, newItemPosition);

And this is my adapter:

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder> {
    private ArrayList<User> mDataset;
    private MyViewHolder myHolder;
    private User user;
    public static class MyViewHolder extends RecyclerView.ViewHolder {
        public TextView singleItemTextView;
        public ImageView singleItemImage;
        public View layout;
        public ConstraintLayout constraintLayout;
        public MyViewHolder(View v) {
            layout = v;
            singleItemImage = (ImageView) v.findViewById(;
            singleItemTextView = (TextView) v.findViewById(;
            constraintLayout = (ConstraintLayout) v.findViewById(;
    // Provide a suitable constructor (depends on the kind of dataset)
    public MyAdapter(ArrayList<User> myDataset) {
        mDataset = myDataset;
    // Create new views (invoked by the layout manager)
    public MyAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent,
                                                     int viewType) {

        View v =  LayoutInflater.from(parent.getContext())
                .inflate(R.layout.nb_image_view, parent, false);
        MyViewHolder vh = new MyViewHolder(v);
        return vh;
    public void onBindViewHolder(final MyViewHolder holder, final int position) {
        myHolder = holder;

        user = mDataset.get(position);
        Uri userImage = user.getImageUrl();       
        Glide.with(myHolder.itemView.getContext() /* context */)
        myHolder.constraintLayout.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {               
                 Context context = v.getContext();                
                Intent intent = new Intent(v.getContext(), DisplayUserActivity.class);
    public void updateList(ArrayList<User> newList) {
        DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(new MyDiffUtilCallBack(this.mDataset, newList));

I am not sure I combine all the classes correctly (my first time using DifUtil), and I also get cannot resolve method updateList(?)

What am I doing wrong?

Sorting of ArrayList shows first item twice

Sorting of ArrayList shows first item twice

i try to Sort my arrayList depending on the distance between user and the locationTo do this i created the following two methods:

How to customize SwipeToReferesh layout top ProgressBar or Loader?

How to customize SwipeToReferesh layout top ProgressBar or Loader?

I would like to know how can I customize SwipeToRefresh layoutIn specific, I am trying to hide that loader

How to solve dlopen failed: library &ldquo;../../lib/; not found error?

How to solve dlopen failed: library “../../lib/” not found error?

I am working on android app with Face Recognization using OpenCvI found this repo here's a link

Dagger 2 get old token when token is refreshed

Dagger 2 get old token when token is refreshed

I am having a problem with dagger 2Briefly, dagger 2 makes the injection in my fragment, and if the token is expired