gpt4 book ai didi

java - firebase UI 更新后无法使 viewholder 最终

转载 作者:行者123 更新时间:2023-12-02 10:56:51 25 4
gpt4 key购买 nike

我将我的 com.firebaseui:firebase-ui-database 包从 1.1.1 更新到 3.3.1。看来我不能再在 FirebaseRecyclerAdapter 中使用 populateViewHolder 了。相反,我应该使用 onBindViewHolder。我认为这很好,但是当我从内部类(另一个数据库引用)中调用 View 持有者时,我需要将 View 持有者设为最终的,此时适配器会出现以下错误:

enter image description here

代码

addedFriendsRecycleViewAdapter = new FirebaseRecyclerAdapter<Boolean, SingleImageViewHolder>(
Boolean.class,
R.layout.adduser_single_round_pictrure_layout,
SingleImageViewHolder.class,
mMembersDatabase
) {
@Override
public SingleImageViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return null;
}

@Override
protected void onBindViewHolder(@NonNull final SingleImageViewHolder holder, int position, @NonNull Boolean model) {
final String added_list_user_id = getRef(position).getKey();

mUsersDatabase.child(added_list_user_id).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {

String userThumb = dataSnapshot.child("thumb_image").getValue().toString();

holder.setImage(userThumb, AddUserActivity.this);

}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});
}
};

最佳答案

您需要在 3.0+ 版本中使用 FirebaseRecyclerOptions:

First, configure the adapter by building FirebaseRecyclerOptions:

 FirebaseRecyclerOptions<POJO> options =
new FirebaseRecyclerOptions.Builder<POJO>()
.setQuery(query, POJO.class)
.build();

Next create the FirebaseRecyclerAdapter object:

FirebaseRecyclerAdapter adapter = new FirebaseRecyclerAdapter<POJO, SingleImageViewHolder>(options) {
@Override
public SingleImageViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// Create a new instance of the ViewHolder, in this case we are using a custom
// layout called R.layout.message for each item
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.message, parent, false);

return new SingleImageViewHolder(view);
}

@Override
protected void onBindViewHolder(SingleImageViewHolder holder, int position, POJO model) {
// Bind the Chat object to the ChatHolder
// ...
}
};

更多详细信息请参见:

https://github.com/firebase/FirebaseUI-Android/tree/master/database

关于java - firebase UI 更新后无法使 viewholder 最终,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51662026/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com