正在从firebase数据库填充RecyclerView



我是Android的新手,正在开发并尝试将Firebase数据库中的数据显示到Recyclerview,但当我运行应用程序时,用户活动为空,或者在我的Recyclerview上没有显示任何内容。

我被卡住了,但输出仍然是一样的:没有显示任何内容。

用户活动:

private Toolbar mToolbar;
private RecyclerView mUsersList;
private DatabaseReference mUsersDatabase;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_users);
mToolbar = (Toolbar) findViewById(R.id.users_appBar);
setSupportActionBar(mToolbar);
getSupportActionBar().setTitle("Users");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mToolbar.setTitleTextColor(Color.WHITE);
mToolbar.setSubtitleTextColor(Color.WHITE);
mUsersDatabase = FirebaseDatabase.getInstance().getReference().child("Users");
mUsersList = (RecyclerView) findViewById(R.id.users_list);
mUsersList.setHasFixedSize(true);
mUsersList.setLayoutManager(new LinearLayoutManager(this));
}
@Override
protected void onStart() {
super.onStart();
FirebaseRecyclerAdapter<Users, UsersViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Users, UsersViewHolder>(
Users.class,
R.layout.users_single_layout,
UsersViewHolder.class,
mUsersDatabase
) {
@Override
protected void populateViewHolder(UsersViewHolder usersViewHolder, Users users, int i) {
usersViewHolder.setName(users.getName());
}
};
mUsersList.setAdapter(firebaseRecyclerAdapter);
}

public static class UsersViewHolder extends RecyclerView.ViewHolder
{
View mView;
public UsersViewHolder(@NonNull View itemView) {
super(itemView);
mView = itemView;
}
public void setName(String name)
{
TextView userNameView = (TextView) mView.findViewById(R.id.user_name);
userNameView.setText(name);
}
}

这是我的Model类中的代码,它是Users

private String name;
private String image;
private 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;
}

您使用的是旧版本的FirebaseUI,需要删除mUsersList.setHasFixedSize(true);才能显示数据

相关内容

  • 没有找到相关文章

最新更新