嗨,请帮忙! 我有listview和Firebase的数据,我想添加搜索栏或searchView来获取名称来自data firebase的电影
答案 0 :(得分:0)
DatabaseReference mDatabase = FirebaseDatabase.getInstance().getReference();
DatabaseReference query = mDatabase.child("Movies");
query.orderByChild("name").startAt(searchText);
query.addListenerForSingleValueEvent(
new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot messageSnapshot: dataSnapshot.getChildren()) {
String name = (String) messageSnapshot.child("name").getValue();
Log.d("TAG", "name is :"+name);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
答案 1 :(得分:0)
要解决此问题,您需要使用如下查询:
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
Query query = rootRef.child("Movies").orderByChild("name").startAt(name).endAt(name + "\uf8ff");
query.addListenerForSingleValueEvent(/* ... */);