如何使用TextWatcher实施Firebase Recycler? [英] How to implement firebase recycler using TextWatcher?

查看:91
本文介绍了如何使用TextWatcher实施Firebase Recycler?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的应用程序中实现了Firebase回收器.使用text watcher时一切正常,但是在 onTextChanged 中,使用键盘向上时,recycler视图不会更新,并且只要按下键盘向下键,即可立即更新.

I have implemented Firebase recycler in my app. 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.

这是我的代码:

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();
        }
    };

这是Firebase回收站:

This is firebase recycler:

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?

推荐答案

就是这样,我的代码中有 mRecyclerView.setHasFixedSize(true); .删除它就可以了.

It is just that, I was having mRecyclerView.setHasFixedSize(true); in my code. Removing this made it work.

这篇关于如何使用TextWatcher实施Firebase Recycler?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆