Android Studio-Firebase-search and edit data
I am creating an app using Android Studio, which stores customer information in Firebase :
I need to create a way to search these clients by name or CPF, in case it is necessary to change something, so I wanted to know if anyone can give any tips or know some interesting tutorial for this..
2
Author: Leonardo Bonetti, 2017-08-23
2 answers
You can find the desired record using a sequential check with the command for , as a code example below:
mDatabase = FirebaseDatabase.getInstance().getReference();
mDatabase.child("clientes").addListenerForSingleValueEvent(new ValueEventListener() {
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot snap : dataSnapshot.getChildren()) {
if (Objects.equals(snap.child("cnpj").getValue(), "999.999.999-99")) {
// seu codigo aqui
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
The above code will read sequentially from the first to the last record and if the cnpj is informed, you can collect the other customer data.
0
Author: Itapox, 2017-09-11 19:17:28
You will have to use a query in Firebase, to be able to filter. Try to do this way:
DatabaseReference ref = FirebaseDatabase.getInstance().getReference("clientes");
Query clienteCnpj = ref.orderByChild("cnpj").equalTo("CNPJ");
clienteCnpj.addValueEventListener( new ValueEventListener(){
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot clienteSnap : dataSnapshot.getChildren() ){
}
}
@Override
public void onCancelled(DatabaseError databaseError) {}
});
0
Author: Grupo CDS Informática, 2017-09-11 19:46:30