执行控件似乎没有放在onCreateViewHolder内部;数据没有显示在屏幕上。 似乎正在调用onStart和onBindViewHolder,但没有调用onCreateViewHolder。
我尝试了很多事情,一直在努力解决2天。我有: 1.删除setHasFixdSize(true),没有用
添加setHasFixedSize(false)也不起作用
将相对布局转换为框架布局,反之亦然。
降级所有firebase依赖项,并使用populateview方法。也不起作用
UsersActivity.java
重要声明:
private RecyclerView usersList;
private DatabaseReference mUsersDatabase;
private FirebaseRecyclerAdapter<Users, UserHolders> firebaseRecyclerAdapter;
在onCreate中:
usersList = (RecyclerView) findViewById(R.id.user_list);
usersList.setHasFixedSize(false);
usersList.setLayoutManager(new LinearLayoutManager(this));
DatabaseReference userRef = FirebaseDatabase.getInstance().getReference().child("Users");
FirebaseRecyclerOptions<Users> options = new FirebaseRecyclerOptions.Builder<Users>()
.setQuery(userRef, Users.class)
.build();
firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Users, UserHolders>(options) {
@Override
protected void onBindViewHolder(UserHolders holder, int position, Users model) {
holder.userName.setText(model.getName());
holder.userStatus.setText(model.getImage());
Picasso.get().load(model.getImage()).into(holder.userProfile);
Toast.makeText(UsersActivity.this, "working onBind", Toast.LENGTH_SHORT).show();
}
@Override
public UserHolders onCreateViewHolder(ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.users_single_layout, viewGroup, false);
UserHolders userHolders = new UserHolders(view);
Toast.makeText(UsersActivity.this, "working onCreate", Toast.LENGTH_SHORT).show();
return userHolders;
}
};
usersList.setAdapter(firebaseRecyclerAdapter);
在onStart()
super.onStart();
Toast.makeText(this, "onStart being called", Toast.LENGTH_SHORT).show();
firebaseRecyclerAdapter.startListening();
在onStop()
super.onStop();
firebaseRecyclerAdapter.stopListening();
ViewHolder类:
public static class UserHolders extends RecyclerView.ViewHolder {
TextView userName, userStatus;
CircleImageView userProfile;
public UserHolders(@NonNull View itemView) {
super(itemView);
userName = itemView.findViewById(R.id.user_single_name);
userProfile = itemView.findViewById(R.id.user_single_image);
userStatus = itemView.findViewById(R.id.user_single_status);
}
}
模型类
public class Users {
public String name;
public String image;
public String status;
public Users(){}
public Users(String name, String image, String status) {
this.name = name;
this.image = image;
this.status = status;}
public String getName() {return name;}
public void setName(String name) {this.name = name;}
public String getImage() {return image;}
public void setImage(String image) {this.image = image;}
public String getStatus() {return status;}
public void setStatus(String status) {this.status = status;}
}
Firebase依赖项:
implementation 'com.google.firebase:firebase-database:16.1.0'
implementation 'com.google.firebase:firebase-storage:16.1.0'
implementation 'com.google.firebase:firebase-auth:16.1.0'
implementation 'com.firebaseui:firebase-ui-database:4.3.2'
因此,我希望所有的敬酒都能正常工作,这表明确实可以编译完整的代码。 调用了onBindViewHolder和onStart内部的敬酒,但未调用onCreateViewHolder内部的敬酒。
所以数据的结构如下
teteatete-c08f9
-Users
-FxFcc..............
.- image
.- name
.- status
.- thumb_image
我检查了模型类变量与这些字段的名称是否相同
答案 0 :(得分:-1)
您的代码似乎很完美。 您是否在Firebase控制台中检查了规则? 将它们从假变为真。 转到Firebase中的实时数据库,然后在规则中将false替换为true。 然后它必须工作。