Android中Firebase数据库的读、写和访问数据

Android中Firebase数据库的读、写和访问数据,android,firebase,firebase-realtime-database,Android,Firebase,Firebase Realtime Database,我已经为学生使用的应用程序创建了一个基本数据库。我希望学生能够使用预定义的用户ID(4位数字)和密码(3个字母)登录。。。。我在Firebase中创建了这个 我尝试了许多组合,但我不知道如何做到以下几点: 检查是否存在id为的用户(例如“1544”) 如果此用户的密码为“rql” 如何以编程方式添加新用户 如何删除找到的用户 如果您能提供帮助,我们将不胜感激。我附上了我的DB样本的截图。多谢各位 编辑:更新。。。。明白了!可以为输入的用户ID检查相应的pw: b1 = (Button) fin

我已经为学生使用的应用程序创建了一个基本数据库。我希望学生能够使用预定义的用户ID(4位数字)和密码(3个字母)登录。。。。我在Firebase中创建了这个

我尝试了许多组合,但我不知道如何做到以下几点:

  • 检查是否存在id为的用户(例如“1544”)
  • 如果此用户的密码为“rql”
  • 如何以编程方式添加新用户
  • 如何删除找到的用户
  • 如果您能提供帮助,我们将不胜感激。我附上了我的DB样本的截图。多谢各位

    编辑:更新。。。。明白了!可以为输入的用户ID检查相应的pw:

    b1 = (Button) findViewById(R.id.loginBtn);
        b1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (rd1.isChecked()) { //logging on as staff successfully takes you to staff main screen
                    Intent i = new Intent(getApplicationContext(), MainStaff.class);
                    startActivity(i);
                }
                if (rd2.isChecked()) {//logging on as student successfully takes you to quiz screen
                    //set up mref to get get the password for username entered
                    DatabaseReference mref = mDatabase.child("student_users").child(e_uname.getText().toString())
                            .child("password");
                    mref.addListenerForSingleValueEvent(new ValueEventListener() {
                        @Override
                        public void onDataChange(DataSnapshot dataSnapshot) {
                                //if password entered matches the username entered, allow access to quiz
                                if (dataSnapshot.getValue().equals(e_pwd.getText().toString())) {
                                    Toast.makeText(getApplicationContext(), "Successfully logged on", Toast.LENGTH_SHORT).show();
                                    Intent i = new Intent(getApplicationContext(), MainQuiz.class);
                                    startActivity(i);
                                } else {
                                    Toast.makeText(getApplicationContext(), "Please check UserID and password.", Toast.LENGTH_SHORT).show();
                                }
                            }
                        @Override
                        public void onCancelled(DatabaseError databaseError) {
                        }
                    });
                }
            }
        });
    

    标记:太宽了。你看过文件了吗?这在firebase文档中是非常明确的定义。你试过什么?我们不会为您编写代码。是的,我确实读过文档,但我能找到的大部分都是JS。不管怎样,像往常一样,当你向别人寻求帮助时,一定要找出答案。我已经用解决方案编辑了上面的内容