如何在Firebase中获得特定的信息 [英] How to get a specific given in Firebase

查看:301
本文介绍了如何在Firebase中获得特定的信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例:我有一个名称,电子邮件的数据库,但是我想知道这个名称是否与我放入 editText
帮助我非常感谢!!

解决方案

首先启动数据库实例

  FirebaseDatabase firebaseDatabase = FirebaseDatabase.getInstance(); 

获取您要执行操作的数据库的引用

  DatabaseReference dbRef = firebaseDatabase.getReference(NAME_OF_DATABASE); 

然后使用此命令获取名称等于editText文本的所有用户。 b
$ b'pre> 查询的查询= profileDbRef
.orderByChild( 名称)
.equalTo(edittext.getText()。的toString() );
query.addValueEventListener(新ValueEventListener(){
@覆盖
公共无效onDataChange(DataSnapshot dataSnapshot){
为(DataSnapshot dataSnapshot1:dataSnapshot.getChildren()){
Log.d(TAG,dataSnapshot1.getKey()+ + dataSnapshot1.getValue(Profile.class)
的ToString());
}
}
}

@Override
public void onCancelled(DatabaseError databaseError){
$ b}
});


Example: I have a database that has name, email, but I want to know if this name matches a value that I put in an editText Help me Thanks so much!!

解决方案

First of all initiate the database instance

FirebaseDatabase firebaseDatabase = FirebaseDatabase.getInstance();

get the reference of your DB where you want to perform the operation

DatabaseReference dbRef = firebaseDatabase.getReference(NAME_OF_DATABASE);

then use this to get all the user with the name equal to the editText text

Query query = profileDbRef
            .orderByChild("name")
            .equalTo(edittext.getText().toString());
    query.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for (DataSnapshot dataSnapshot1 : dataSnapshot.getChildren()) {
                Log.d(TAG, dataSnapshot1.getKey() + "  " + dataSnapshot1.getValue(Profile.class)
                        .toString());
               }
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });

这篇关于如何在Firebase中获得特定的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆