简体   繁体   English

如何使用TextWatcher实现Firebase Recycler?

[英]How to implement firebase recycler using TextWatcher?

I have implemented Firebase recycler in my app. 我已经在我的应用程序中实现了Firebase回收器。 Everything works fine while using text watcher, but recycler view is not updating in onTextChanged with the keyboard up, and gets updated as soon as i press the keyboard to go down. 使用text watcher时一切正常,但是recycler视图在onTextChangedonTextChanged随着键盘向上的更新而更新,并且一旦我按下键盘向下时就会更新。

This is my code: 这是我的代码:

private TextWatcher textWatcher = new TextWatcher() {

        public void afterTextChanged(Editable s) {
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before,
                                  int count) {
            if(s.toString().trim().length()<1)
            {
                mRecyclerView.setVisibility(View.GONE);
            }
            else
            {
                mRecyclerView.setVisibility(View.VISIBLE);
                firebaseSearch(s.toString());
            }
            Toast.makeText(ChooseUser.this,s.toString(),Toast.LENGTH_SHORT).show();
        }
    };

This is firebase recycler: 这是Firebase回收站:

private void firebaseSearch(String searchText)
    {
        Query firebaseSearchQuery = databaseReference
                .orderByChild("Name")
                .startAt(searchText.toLowerCase())
                .endAt(searchText.toLowerCase() + "\uf8ff");

        FirebaseRecyclerOptions<Users> options =
            new FirebaseRecyclerOptions.Builder<Users>()
                    .setQuery(firebaseSearchQuery, snapshot ->
                            new Users(snapshot.child("Name").getValue().toString(),
                            snapshot.child("Image").getValue().toString(),
                                    snapshot.getKey(),
                                    snapshot.child("Profile").getValue().toString()
                            ))
                    .build();

        firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Users, UsersViewHolder>(
                options
        ) {
            @Override
            protected void onBindViewHolder(@NonNull UsersViewHolder holder, int position, @NonNull Users model) {

                    holder.setDetails(getApplicationContext(), model.getName(), model.getImage());

            }

            @NonNull
            @Override
            public UsersViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
                View view = LayoutInflater.from(parent.getContext())
                        .inflate(R.layout.search_list_items, parent, false);

                return new UsersViewHolder(view);
            }
        };
        firebaseRecyclerAdapter.startListening();
        mRecyclerView.setAdapter(firebaseRecyclerAdapter);
    }

Is there anything to change in my code to update the view dynamically as I enter the words and to show recycler when the keyboard is up? 输入代码时,代码中是否需要更改以动态更新视图并在键盘启动时显示回收站?

It is just that, I was having mRecyclerView.setHasFixedSize(true); 只是,我有mRecyclerView.setHasFixedSize(true); in my code. 在我的代码中。 Removing this made it work. 删除它使它起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM