[英]read data from firebase and set the value of textview
i faced an issue like user entered enrollment number and verify and read all data from that and set the value to text view我遇到了一个问题,比如用户输入了注册号并验证并从中读取所有数据并将值设置为文本视图
If user enter enrollment 66 then verify that enrollment and read all that data from 66 and set value of text view to marks of subjects.what i need to do if i want to solve Above problem?如果用户输入注册 66,然后验证注册并从 66 读取所有数据并将文本视图的值设置为主题的标记。如果我想解决上述问题,我需要做什么?
I tried:我试过了:
reff= FirebaseDatabase.getInstance().getReference().child("Marks");
reff.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
String mm=dataSnapshot.child("mcad").getValue().toString();
String jm=dataSnapshot.child("java").getValue().toString();
String nm=dataSnapshot.child("nma").getValue().toString();
txtmcadmarks.setText(nm);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
First, your Database Reference returns you a list of data so you need to receive your data as a list.首先,您的数据库引用会返回一个数据列表,因此您需要将数据作为列表接收。
Second, if you want to filter your data base on enrollment
then add a query in your database reference.其次,如果您想根据enrollment
过滤您的数据库,请在您的数据库参考中添加一个查询。
DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference();
Query query = databaseReference.child("Marks").orderByChild("enrollment").equalTo(66);
query.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot data: dataSnapshot.getChildren()){
String mm=data.child("mcad").getValue().toString();
String jm=data.child("java").getValue().toString();
String nm=data.child("nma").getValue().toString();
txtmcadmarks.setText(nm);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.