我是 Android 開發(fā)新手,并試圖將數(shù)據(jù)從 Firebase 數(shù)據(jù)庫顯示到 Recyclerview,但是當(dāng)我運(yùn)行該應(yīng)用程序時(shí),用戶活動(dòng)為空白或在我的 RecyclerView 上沒有顯示任何內(nèi)容。我被卡住了,但輸出仍然相同:沒有顯示任何內(nèi)容。用戶活動(dòng):private Toolbar mToolbar;private RecyclerView mUsersList;private DatabaseReference mUsersDatabase;@Overrideprotected 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));}@Overrideprotected 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); }}
1 回答

哈士奇WWW
TA貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超6個(gè)贊
您使用的是舊版本的 FirebaseUI,您需要?jiǎng)h除mUsersList.setHasFixedSize(true);
才能顯示數(shù)據(jù)
添加回答
舉報(bào)
0/150
提交
取消