So I have problem like [this](https://media.giphy.com/media/Sqm08qFb11lEfMyc1q/giphy.gif)

I'm using recyclerview inside viewpager with tablayout. It's working fine when activity launched but when i navigate to the last tab and comeback again to the tab where recyclerview inside it the item is duplicating.

Her is my TabAdapter:

```
public class TabAdapter extends FragmentPagerAdapter {

private Context mContext;

public TabAdapter(Context context, FragmentManager fragmentManager) {
    super(fragmentManager);
    mContext = context;
}

@Override
public Fragment getItem(int position) {
    switch (position) {
        case 0:
            return new CameraTabFragment();
        case 1:
            return new ChatTabFragment();
        case 2:
            return new StatusTabFragment();
        default:
            return new CallsTabFragment();

    }
}

@Override
public int getCount() {
    return 4;
}

@Nullable
@Override
public CharSequence getPageTitle(int position) {
    if (position == 0) {
        return null;
    } else if (position == 1) {
        return "Chats";
    } else if (position == 2) {
        return "Status";
    } else {
        return "Calls";
    }
}}

```

My fragment with recyclerview:

```
public class ChatTabFragment extends Fragment {

private RecyclerView mRecyclerView;
private FirebaseDatabase mFirebaseDatabase;
private DatabaseReference mConversationReference;
private DatabaseReference mChatReference;
private DatabaseReference mUserReference;
private FirebaseAuth mAuth;
private FirebaseUser mFirebaseUser;
private ChatListAdapter mAdapter;

private String personId;
private String key;

private List<User> userList = new ArrayList<>();
private List<Chat> chatList = new ArrayList<>();
private List<Conversation> conversationList = new ArrayList<>();

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_chat_tab, container, false);

    mRecyclerView = rootView.findViewById(R.id.recyvlerview_chat_tab);

    RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity());
    mRecyclerView.setLayoutManager(layoutManager);
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());

    mFirebaseDatabase = FirebaseDatabase.getInstance();
    mAuth = FirebaseAuth.getInstance();

    mFirebaseUser = mAuth.getCurrentUser();

    mChatReference = mFirebaseDatabase.getReference().child("chats");
    mConversationReference = mFirebaseDatabase.getReference().child("conversation").child(mFirebaseUser.getUid());
    mUserReference = mFirebaseDatabase.getReference().child("users");
 mConversationReference.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
                Conversation conversation = snapshot.getValue(Conversation.class);
                conversationList.add(conversation);

                key = snapshot.getKey();
                personId = snapshot.child("chatWithId").getValue(String.class);

                Query query = mUserReference.orderByKey().equalTo(personId);
                query.addValueEventListener(new ValueEventListener() {
                    @Override
                    public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                        for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
                            User user = snapshot.getValue(User.class);
                            userList.add(user);
                        }

                        mAdapter = new ChatListAdapter(getActivity(),  userList);
                        mRecyclerView.setAdapter(mAdapter);

                    }

                    @Override
                    public void onCancelled(@NonNull DatabaseError databaseError) {

                    }
                });
            }

        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {

        }
    });
return rootView;
}

```

}

and this is my recyclerview adapter:

```
public class ChatListAdapter extends RecyclerView.Adapter<ChatListAdapter.MyViewHolder> {

private FirebaseAuth mAuth;
private FirebaseUser mFirebaseUser;

private List<Conversation> conversationList;
private List<User> userList;

private Context mContext;

public ChatListAdapter(Context context,  List<User> users) {
    this.mContext = context;
    this.userList = users;
}

@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_chats, parent, false);
    return new MyViewHolder(view);
}

@Override
public void onBindViewHolder(@NonNull final MyViewHolder holder, final int position) {

    User user = userList.get(position);

    holder.username.setText(user.getUsername());
    Glide.with(mContext)
            .load(user.getPhotoUrl())
            .into(holder.avatar);
    holder.layout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            User user1 = userList.get(position);
            Intent intent = new Intent(mContext, ChatRoomActivity.class);
            intent.putExtra("userUid", user1.getUid());
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
            mContext.startActivity(intent);
        }
    });
}

@Override
public int getItemCount() {
    return userList.size();
}

public class MyViewHolder extends RecyclerView.ViewHolder {
    private TextView username;
    private TextView message;
    private CircleImageView avatar;
    private RelativeLayout layout;

    public MyViewHolder(@NonNull View itemView) {
        super(itemView);
        username = itemView.findViewById(R.id.tv_username);
        message = itemView.findViewById(R.id.tv_message);
        avatar = itemView.findViewById(R.id.avatar_user);
        layout = itemView.findViewById(R.id.layout_user_chat);
    }
}}

```

How can i fix this? Thanks.