如何从Firebase数据中过滤编辑文本?

时间:2019-03-08 10:23:24

标签: android firebase firebase-realtime-database

这是我从中获得文本的代码:

etSearchFriends = (EditText) findViewById(R.id.etSearchFriends);


        buttonSearch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                searchText = etSearchFriends.getText().toString();
                filterLocation(searchText);
            }
        });

这是应该在其中运行代码的过滤器,但遗憾的是,

private void filterLocation(final String s) {
    final ArrayList<User> users = new ArrayList<>();
    Log.d("UserData1",s);

    fRef.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for (DataSnapshot dataSnapshot1 : dataSnapshot.getChildren()) {
                fname = dataSnapshot1.child("fname").getValue(String.class);
            }
                for (User user1 : ListOfBranches.getUsers()) {
                    if (fname.toLowerCase().contains(s)) {
                        users.add(user1);
                        Log.d("UserData3", dataSnapshot.getValue(String.class));
                    }
                }
                friendsAdapter.filterLocation(users);


        }

这是从数据库中提取其他数据的列表:

    userRef = FirebaseDatabase.getInstance().getReference().child("UserFiture");

        userRef.addChildEventListener(new ChildEventListener() {
            @Override
            public void onChildAdded(DataSnapshot dataSnapshot, String s) {
//                User user1 = dataSnapshot.getValue(User.class);
                User u = new User();
                String fname = dataSnapshot.child("fName").getValue(String.class);
                String lname = dataSnapshot.child("lName").getValue(String.class);
                String age = dataSnapshot.child("age").getValue(String.class);
                String gender = dataSnapshot.child("gender").getValue(String.class);

                u.setfName(fname);
                u.setlName(lname);
                u.setAge(age);
                u.setGender(gender);
                users.add(u);
                Log.e("dataSnapshot", String.valueOf(u));
            }

我想在这里获取所有数据,并在搜索文本等于fname的情况下显示它: enter image description here

0 个答案:

没有答案