D
D
DARKENN2020-01-12 22:47:05
Java
DARKENN, 2020-01-12 22:47:05

How to make an element fade in Recycler View?

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_game);
        mAuth = FirebaseAuth.getInstance();
        mDatabase = FirebaseDatabase.getInstance().getReference();
        firebaseUser = mAuth.getCurrentUser();
        database = FirebaseDatabase.getInstance();
        connectReference = database.getReference();
        myBase = mDatabase.child("chat");
        buttonSend = findViewById(R.id.send_btn);
        mMessagesRecycler = findViewById(R.id.chat);
        mMessagesRecycler.setLayoutManager(new LinearLayoutManager(this));
        final ChatAdapter dataAdapter = new ChatAdapter(result);
        mMessagesRecycler.setAdapter(dataAdapter);
        buttonSend.setOnClickListener(new OnClickListener() {
            public void onClick(View view) {
                sendText = findViewById(R.id.message_input);
                FirebaseDatabase.getInstance().getReference().child("chat").push().setValue(new ChatModel(
                        sendText.getText().toString(), "Админ"));
                sendText.setText("");
            }
        });
        myBase.addChildEventListener(new ChildEventListener() {
            public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
                result.add(dataSnapshot.getValue(ChatModel.class));
                dataAdapter.notifyDataSetChanged();
                mMessagesRecycler.smoothScrollToPosition(result.size());
            }

            public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
            }

            public void onChildRemoved(@NonNull DataSnapshot dataSnapshot) {
            }

            public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
            }

            public void onCancelled(@NonNull DatabaseError databaseError) {
            }
        });
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2020-01-13
@DARKENN

You need to use notifyDataSetChanged, but other methods - notifyItemlnserted, and so on. DiffUtil will help with this. Standard animations will work. And if you need custom animations, you need to write your own ItemAnimator.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question