I was Trying to add childs(Programmes) to the Above reference STUDENTS.
So the issue is when I retrieve the keys and add them to the ArrayList of Strings.
And check Whether it Matches the entered Text it gives ; Like Example; in the photo, we have Three Programmes bps,cs,mm.
it gives me matches, not matches,not matches result what I want is whether it matches or not like as above.
CODE
// retreiving the edittext to String String prnamez = programmeName.getEditableText().toString().trim().toLowerCase(); // checking if the program already exists FirebaseAuth autha = FirebaseAuth.getInstance(); DatabaseReference dnn = FirebaseDatabase.getInstance() .getReference("Admin").child(autha.getUid()).child("INSTITUTE") .child("STUDENTS"); // arraylist to add the keys of the programme ArrayList<String> pgName = new ArrayList<>(); // value event listener dnn.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(@NonNull DataSnapshot snapshot) { if (snapshot.exists()) { progressBar.setVisibility(View.VISIBLE); // going through all the keys and adding them to the arraaylist of pgName for (DataSnapshot regis : snapshot.getChildren()) { // retrieved the programme Name pgName.add(regis.getKey().toString()); } // going through the lenght of the array list for (int i = 0; i < pgName.size(); i++) { // if the entered programme matches already existing programme name // then show this custom Toast if (pgName.get(i).equals(prnamez)) { // custom Toast StyleableToast.makeText(Programme_students.this, "Matches", R.style.exampleToast).show(); } else { StyleableToast.makeText(Programme_students.this, "not Matches", R.style.exampleToast).show(); // WANT TO ADD NEW PROGRAMME IN THIS CASE } } } } @Override public void onCancelled(@NonNull DatabaseError error) { } }); } }); https://stackoverflow.com/questions/66739330/not-allowing-users-add-same-named-child-firebase-android March 22, 2021 at 09:38AM

没有评论:
发表评论