搜索数据名​​称Firebase ListView Android

时间:2018-07-11 11:39:41

标签: android firebase listview firebase-realtime-database android-adapter

嗨,请帮忙! 我有listview和Firebase的数据,我想添加搜索栏或searchView来获取名称来自data firebase的电影

This is my data in firabase

2 个答案:

答案 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(/* ... */);