【发布时间】:2020-04-22 22:14:34
【问题描述】:
我正在尝试开发与学校相关的应用程序。这是我的数据库的图片。在我的代码中,我将 schoolEmail 作为字符串(即字符串电子邮件 = iisd@gmail.com)。我想用这个字符串知道这封邮件属于哪个学校(在这种情况下是IISD)我想把这个值作为字符串。
请看这张照片
这是我的代码
public class HomeScreen extends AppCompatActivity {
TextView schoolName,schoolEmail,schoolPhone,schoolAddress;
Button logoutSchool;
DatabaseReference databaseReference;
String email;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_screen);
schoolName = findViewById(R.id.schoolName);
schoolEmail = findViewById(R.id.schoolEmail);
schoolPhone = findViewById(R.id.schoolPhone);
schoolAddress = findViewById(R.id.schoolAddress);
logoutSchool = findViewById(R.id.loginSchool);
databaseReference = FirebaseDatabase.getInstance().getReference();
email = "iisd@gmail.com";
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// This method is called once with the initial value and again
// whenever data at this location is updated.
DataSnapshot dataSnapshot1 = dataSnapshot.getChildren();
String value = dataSnapshot.child("Schools").getKey();
Toast.makeText(HomeScreen.this, value, Toast.LENGTH_SHORT).show();
}
@Override
public void onCancelled(DatabaseError error) {
}
});
}
}
【问题讨论】:
-
所以你想让IISD依赖于学校,并且在此之下,它会有某些信息?
-
“学校”将保持不变,所有学校都将添加到其中。我想添加更多的学校,每个学校都会有一个email,所以我想用这个email来获取学校名称
标签: android firebase firebase-realtime-database firebase-authentication