请注意,它会进入onDataChange
var userPrefix: String = getUserPrefix()
Log.d("usePRef",userPrefix + " x ")
var sp: SimPrefix //SimPrefix Data Class
var query: Query = mDatabaseReference.child("simnumbers")
.orderByChild("simPref")
.equalTo(userPrefix)
.limitToFirst(1)
query.addValueEventListener( object : ValueEventListener {
override fun onDataChange(dataSnapshot: DataSnapshot) {
for (finalSnap in dataSnapshot.children) {
sp = finalSnap.getValue(SimPrefix::class.java)!! //passing the object to another
//data class object
resultView.text = sp.simCard // displaying the value to a TextView
}
}
override fun onCancelled(databaseError: DatabaseError) {
println("loadPost:onCancelled ${databaseError.toException()}")
}
})
}
但是,firebase查询没有返回任何内容。
答案 0 :(得分:2)
我提供了java代码,你可以根据这些代码改变你的价值。
private void sqlQuery(){
DatabaseReference reference = FirebaseDatabase.getInstance().getReference();
Query query = reference.child("simnumbers").child(mFirebaseDatabase.push().getKey()).orderByChild("simPref").equalTo("value");
query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
for (DataSnapshot issue : dataSnapshot.getChildren()) {
Log.d("Value::",issue.getValue(User.class).email);
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}