android - 不允许用户添加相同的命名子 Firebase Android?
问题描述
我试图将孩子(程序)添加到上述参考学生中。
所以问题是当我检索密钥并将它们添加到字符串的 ArrayList 时。
并检查它是否与它给出的输入文本匹配;像例子; 在照片中,我们有三个程序 bps,cs,mm。
它给了我匹配,不匹配,不匹配的结果我想要的是它是否像上面那样匹配。
代码
// 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) {
}
});
}
});
解决方案
推荐阅读
- amazon-web-services - 无法使用 OpenAPI 3.0.0 规范执行基本验证
- laravel - 我正在寻找自定义 laravel 默认身份验证的最佳方法
- python - 链接的 Python 版本错误
- python - 混淆所有hadler的日志输出
- hadoop - 从 hdfs cli 查询时,纱线站点配置返回奇异值
- swift - 初始化问题之前使用的另一个变量“__”
- javascript - jQuery/Javascript - 当浏览器控制台中的 val 发生变化时检测选择选项的变化
- javascript - NextJS:迄今为止的纪元时间
- python - 匹配键和更新嵌套字典值的结果与预期不符
- html - 如何让这个元素显示在其他所有内容之上?