我正在创建一个应用程序,学生将使用该应用程序扫描由教师创建的类的QR代码。
学生扫描后,她/他的详细信息将存储在班级列表数据中。我的问题是当我尝试更改名字,中间名和姓氏时,只有第一个框正在更新,而第二个和第三个框则没有。
有人可以帮帮我吗?
以下是更新第一个框的代码:
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
String uid = user.getUid();
ref = FirebaseDatabase.getInstance().getReference();
ref.child("users").child("student").child(uid).addListenerForSingleValueEvent(new ValueEventListener() {
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
String uid = user.getUid();
String newFirstName = oldEmail.getText().toString().trim();
String newMiddleName = middlename.getText().toString().trim();
String newLastName = lastname.getText().toString().trim();
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
ref.child("users").child("student").child(uid).child("firstname").setValue(newFirstName);
ref.child("users").child("student").child(uid).child("middlename").setValue(newMiddleName);
ref.child("users").child("student").child(uid).child("lastname").setValue(newLastName);
progressBar.setVisibility(View.GONE);
}
@Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(AccountSettingsActivity.this, "Failed to update name!", Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.GONE);
}
});
以下是更新第二个和第三个框的代码:
ref.child("users").child("teacher").child("class").child("Listofstudents").child(user.getUid().toString().trim()).addListenerForSingleValueEvent(new ValueEventListener() {
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
String uid = user.getUid();
String newFirstName = oldEmail.getText().toString().trim();
String newMiddleName = middlename.getText().toString().trim();
String newLastName = lastname.getText().toString().trim();
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
ref.child("users").child("teacher").child(ref.child("teacher").getKey()).child("class").child(ref.child("class").getKey()).child("Listofstudents").child(user.getUid().toString().trim()).child("firstname").setValue(newFirstName);
ref.child("users").child("teacher").child(ref.child("teacher").getKey()).child("class").child(ref.child("class").getKey()).child("Listofstudents").child(user.getUid().toString().trim()).child("middlename").setValue(newMiddleName);
ref.child("users").child("teacher").child(ref.child("teacher").getKey()).child("class").child(ref.child("class").getKey()).child("Listofstudents").child(user.getUid().toString().trim()).child("lastname").setValue(newLastName);
// TODO: handle the case where the data already exists
}
else {
// TODO: handle the case where the data does not yet exist
}
}
@Override
public void onCancelled(DatabaseError firebaseError) {
Toast.makeText(AccountSettingsActivity.this, "Failed to update name!", Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.GONE);
}
});