构建用户活动,尝试从数据库(名称、已售商品和日期)中检索特定信息,从所有用户类和我的数据库参考中获取此信息,并将其显示在我的应用程序的 Recyclerview 中。
我的数据库
为此https://github.com/firebase/FirebaseUI-Android/尝试了 FirebaseUI-Android
我的应用程序崩溃了!
我的代码:
@Override
protected void onStart() {
super.onStart();
startListening();
}
public void startListening(){
Query query = FirebaseDatabase.getInstance()
.getReference()
.child("Users")
.limitToLast(50);
FirebaseRecyclerOptions<ALL_USERS> options =
new FirebaseRecyclerOptions.Builder<ALL_USERS>()
.setQuery(query, ALL_USERS.class)
.build();
FirebaseRecyclerAdapter adapter = new FirebaseRecyclerAdapter<ALL_USERS, UsersViewHolder>(options) {
@Override
public UsersViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.users_card_layout, parent, false);
return new UsersViewHolder(view);
}
@Override
protected void onBindViewHolder(@NonNull UsersViewHolder usersViewHolder, int i, @NonNull ALL_USERS all_users) {
usersViewHolder.setName(all_users.getName());
}
};
mUsersList.setAdapter(adapter);
adapter.startListening();
}
public static class UsersViewHolder extends RecyclerView.ViewHolder{
View mView;
public UsersViewHolder(View itemView) {
super(itemView);
mView=itemView;
}
public void setName(String name){
TextView userNameView = mView.findViewById(R.id.Users_Name);
userNameView.setText(name);
}
}
}
一只甜甜圈
相关分类