【发布时间】:2020-10-11 17:26:26
【问题描述】:
我试图让 i 的值增加,但它似乎只是在这里重复 2 的值。我认为它应该保持递增 1,因为我在开始时将值设置为 1,但此处未显示,因为它靠近我的班级顶部..
public void onDataChange(@NonNull DataSnapshot snapshot) {
for (DataSnapshot childSnapshot : snapshot.getChildren()) {
String clinic_info = String.valueOf(childSnapshot.child("Name").getValue());
String txt_review = review.getText().toString();
String txt_dorevitch = dorevitch.getText().toString();
String txt_skin_cancer = skin_cancer_check.getText().toString();
String txt_ear_suctioning = ear_suctioning.getText().toString();
message[0] = message[0].split("\\s*:\\s*")[0]; // use this to get the name of the clinic only..
// replace(":" ,"");
// message[0] = message[0].replaceAll("[0-9]" ,"");
// message[0] = message[0].replace("Shop" ,"");
//
assert clinic_info != null;
if (clinic_info.equals(message[0])) {
HashMap<String, Object> map = new HashMap<>();
map.put("Review" + i, txt_review);
i = (int)snapshot.getChildrenCount();
i++;
System.out.println(i);
FirebaseDatabase.getInstance("https://medical-review-in-australia.firebaseio.com/").getReference().child(message[0]).updateChildren(map);
Toast.makeText(Add_Review.this, "Review Successfully Submited", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(Add_Review.this, "There was an error while updating the database, please try again.", Toast.LENGTH_SHORT).show();
}
【问题讨论】:
-
由于某种原因,它要么停在特定的数字上,要么被覆盖......
标签: java android firebase-realtime-database