[英]i want to fetch data full in a single Textview from firebase database
I have created a barcode scanner app and it reads the barcode id and needed the output as voice output.我创建了一个条形码扫描仪应用程序,它读取条形码 ID 并需要输出作为语音输出。 in order to read all the things i need to fetch all data together in one single
TextView
.为了阅读我需要在一个
TextView
获取所有数据的所有内容。 I did my level best to add the query from database.我尽我所能从数据库中添加查询。 but it only shows in
TextView
as com.google.firebase.database.Query@9fc9e4d
and my app TTS
engine reads it clearly.但它只在
TextView
显示为com.google.firebase.database.Query@9fc9e4d
并且我的应用TTS
引擎可以清楚地读取它。 But i need to set it as all data under a single TextView
from database to speak out.但是我需要将其设置为数据库中单个
TextView
下的所有数据才能说出来。 please help me????请帮我???? here only i attached the result handling method.
这里只有我附上了结果处理方法。
@Override
public void handleResult(Result result) { final String scanResult = result.getText();
databasefetch = FirebaseDatabase.getInstance().getReference("save");
databasefetch.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
setContentView(R.layout.activity_second);
TextView text = (TextView) findViewById(R.id.textView3);
String tst = databasefetch.child("save").orderByChild("id").equalTo(scanResult).toString();
text.setText(tst);
//text to speech
String toSpeak=text.getText().toString();
//Toast.makeText(getApplicationContext(),toSpeak,Toast.LENGTH_SHORT).show();
txt.speak(toSpeak,TextToSpeech.QUEUE_FLUSH,null);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
Try something like this尝试这样的事情
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot postSnapshot: dataSnapshot.getChildren()) {
// TODO: handle the post
YourModelClass object = postSnapshot.getValue(YourModelClass.class);
text.setText(object.getId().equalsIgnoreCase(scanResult) ? object.getDescription() : "");
}
}
No need to run multiple query to filter the data based on id
.无需运行多个查询来根据
id
过滤数据。 Check below:检查以下:
databasefetch = FirebaseDatabase.getInstance().getReference("save");
databasefetch.orderByChild("id").equalTo(scanResult).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
String toSpeak = "";
for (DataSnapshot childSnapshot: dataSnapshot.getChildren()) {
String name = childSnapshot.child("name").getValue(String.class);
String price = childSnapshot.child("price").getValue(String.class);
String details = childSnapshot.child("details").getValue(String.class);
toSpeak = name + ", " + price + ", " + details;
}
text.setText(toSpeak);
txt.speak(toSpeak, TextToSpeech.QUEUE_FLUSH,null);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.