当firebase ui升级到3.2.2时输出未显示

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了当firebase ui升级到3.2.2时输出未显示相关的知识,希望对你有一定的参考价值。

当我将firebase-ui版本升级到3.2.2时,firebaserecycleradapter不显示任何输出我的代码。起初当我得到multidex错误然后我将所有库版本升级到应用程序lvl gradle依赖的最新版本,升级后问题找到Firebaserecycleradapter方法然后我搜索它并在运行应用程序后写入列表视图不显示plz帮助我。

在onStart():

 @Override
    protected void onStart() {
        super.onStart();

        FirebaseRecyclerOptions <Users> options = new FirebaseRecyclerOptions.Builder<Users>()
                .setQuery(mUserDatabase,Users.class)
                .build();
        FirebaseRecyclerAdapter<Users, UsersViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Users, UsersViewHolder>(options) {
            @NonNull
            @Override
            public UsersViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
                View view = LayoutInflater.from(parent.getContext())
                        .inflate(R.layout.user_list_layout, parent, false);
                return new UsersViewHolder(view);
            }

            @Override
            protected void onBindViewHolder(@NonNull UsersViewHolder holder, int position, @NonNull Users model) {
                holder.setName(model.getName());
                holder.setStatus(model.getStatus());
                holder.setRIDNo(model.getRidno());
                holder.setUserImage(model.getThumb_image(), getApplicationContext());

                //to get key
                final String user_id = getRef(position).getKey();

                holder.mView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Intent profileIntent = new Intent(UsersActivity.this, ProfileActivity.class);
                        profileIntent.putExtra("user_id", user_id);
                        startActivity(profileIntent);

                    }
                });
            }

        };
        mUsersList.setAdapter(firebaseRecyclerAdapter);

    }

并且视图符号是:

//User list viewholder
    public static class UsersViewHolder extends RecyclerView.ViewHolder {

        static View mView;
        private CircleImageView mUserView;

        public UsersViewHolder(View itemView) {
            super(itemView);

            mView = itemView;
        }

        public static void setName(String name){
            TextView userNameView = (TextView) mView.findViewById(R.id.user_single_name);
            userNameView.setText(name);
        }
        public static void setStatus(String status){
            TextView userStatusView = (TextView) mView.findViewById(R.id.user_single_status);
            userStatusView.setText(status);
        }
        public static void setRIDNo(String ridno){
            TextView userRIDNoView = (TextView) mView.findViewById(R.id.user_single_ridno);
            userRIDNoView.setText(ridno);
        }
        public static void setUserImage(String thumb_image, Context ctx){
            CircleImageView userImageView = (CircleImageView) mView.findViewById(R.id.user_single_image);
            Picasso.with(ctx).load(thumb_image).placeholder(R.drawable.default_avatar).into(userImageView);
        }
    }
答案

为了使您的代码有效,请考虑使用以下步骤。

  1. static类的声明中删除UsersViewHolder。应该只是: public class UsersViewHolder extends RecyclerView.ViewHolder {/* ... */}
  2. static字段和所有方法中删除mView关键字。您的持有人类应如下所示: public class UsersViewHolder extends RecyclerView.ViewHolder { private View mView; private CircleImageView mUserView; public UsersViewHolder(View itemView) { super(itemView); mView = itemView; } public void setName(String name){ TextView userNameView = (TextView) mView.findViewById(R.id.user_single_name); userNameView.setText(name); } public void setStatus(String status){ TextView userStatusView = (TextView) mView.findViewById(R.id.user_single_status); userStatusView.setText(status); } public void setRIDNo(String ridno){ TextView userRIDNoView = (TextView) mView.findViewById(R.id.user_single_ridno); userRIDNoView.setText(ridno); } public void setUserImage(String thumb_image, Context ctx){ CircleImageView userImageView = (CircleImageView) mView.findViewById(R.id.user_single_image); Picasso.with(ctx).load(thumb_image).placeholder(R.drawable.default_avatar).into(userImageView); } }
  3. 移动除了这行代码之外的onCreate()方法中的onStart()方法的所有代码: super.onStart();
  4. 让你的qazxsw poi变量全局: qazxsw poi
  5. 从onCreate()方法中删除firebaseRecyclerAdapter
  6. private FirebaseRecyclerAdapter<Users, UsersViewHolder> firebaseRecyclerAdapter; FirebaseRecyclerAdapter<Blog, BlogViewHolder>方法中添加以下代码行。 onStart()
  7. 如果您使用身份验证,请不要忘记在onStop()方法中添加以下代码行: @Override protected void onStart() { super.onStart(); firebaseRecyclerAdapter.startListening(); } @Override protected void onStop() { super.onStop(); if(firebaseRecyclerAdapter != null) { firebaseRecyclerAdapter.stopListening(); } }

以上是关于当firebase ui升级到3.2.2时输出未显示的主要内容,如果未能解决你的问题,请参考以下文章

Firebase Ui auth版本3.2.2 xml错误

使用 Firebase 从不同的集合中获取数据,并在数据更改时更新 UI

当使用Firebase和onesignal时,应用程序在第一次运行时崩溃

当来自 Firebase 时,颤动文本输出不抛出段落行

Firebase 身份验证 UI - 登录与注册

怎么证明未显式定义构造方法时,编译器会自动生成无参的构造方法?