How can I change an exist list, to a new list? || android - firebase realtime database

androidForEveryone :

I want to change the exist “categories” list, to a new list.

I know that my problem is in the “setPriority()”, but I don’t find the right method.

My Database Structure:

enter image description here

My code:

private void updateData() {
            database = FirebaseDatabase.getInstance();
            mDatabaseRef = database.getReference();


            mDatabaseRef
                    .child("users")
                    .child(Login.userId)
                    .child("categories")
                    .setValue(categories)
                    .addOnCompleteListener(new OnCompleteListener<Void>() {
                        @Override
                        public void onComplete(@NonNull Task<Void> task) {

                            if (task.isSuccessful()) {

                                //Update success
                            } else {

                                //Update fail
                            }
                        }
                    });
        }

Thank you.

Md. Asaduzzaman :

No need to query to database to update list. You can simply call setValue to over write the existing list with new one. Check below:

database = FirebaseDatabase.getInstance();
mDatabaseRef = database.getReference();

mDatabaseRef
    .child("users")
    .child(Login.userId)
    .child("categories")
    .setValue(categories)
    .addOnCompleteListener(new OnCompleteListener<Void>() {
        @Override
        public void onComplete(@NonNull Task<Void> task) {

            if (task.isSuccessful()) {

                //Update success
            } else {

                //Update fail
            }
        }
    });

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=11399&siteId=1