当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);
}
}
答案
为了使您的代码有效,请考虑使用以下步骤。
- 从
static
类的声明中删除UsersViewHolder
。应该只是:public class UsersViewHolder extends RecyclerView.ViewHolder {/* ... */}
- 从
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); } }
- 移动除了这行代码之外的onCreate()方法中的
onStart()
方法的所有代码:super.onStart();
- 让你的qazxsw poi变量全局: qazxsw poi
- 从onCreate()方法中删除
firebaseRecyclerAdapter
。 - 在
private FirebaseRecyclerAdapter<Users, UsersViewHolder> firebaseRecyclerAdapter;
和FirebaseRecyclerAdapter<Blog, BlogViewHolder>
方法中添加以下代码行。onStart()
- 如果您使用身份验证,请不要忘记在
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