My AdapterClass
public class ShayariAdapter extends FirestoreRecyclerAdapter<ShayariModel, ShayariAdapter.ShayariViewHolder> {
private OnItemClickListener listener;
public interface OnItemClickListener {
void onItemClick(DocumentSnapshot documentSnapshot, int position);
}
public void setOnItemClickListener(OnItemClickListener listener) {
this.listener = listener;
}
public ShayariAdapter(@NonNull FirestoreRecyclerOptions<ShayariModel> options) {
super(options);
}
@Override
protected void onBindViewHolder(@NonNull ShayariViewHolder holder, int position, @NonNull ShayariModel model) {
holder.body.setText(model.getBody());
holder.category.setText(model.getCategory());
holder.author.setText(model.getAuthor());
}
@NonNull
@Override
public ShayariViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.shayari_card, parent, false);
return new ShayariViewHolder(view);
}
class ShayariViewHolder extends RecyclerView.ViewHolder {
TextView body, author;
TextView category;
ImageView shareShayari;
public ShayariViewHolder(@NonNull View itemView) {
super(itemView);
body = itemView.findViewById(R.id.shayariText);
category = itemView.findViewById(R.id.category);
author = itemView.findViewById(R.id.authorName);
shareShayari = itemView.findViewById(R.id.shareShayari);
shareShayari.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int position = getAdapterPosition();
if (position != RecyclerView.NO_POSITION && listener != null) {
listener.onItemClick(getSnapshots().getSnapshot(position), position);
}
}
});
}
}
}
我无法在回收器视图项目之间添加广告,因为有简单适配器的教程,但找不到 FirebaseUI 回收器视图适配器的教程
我尝试过谷歌代码实验室教程,但卡在getItemViewType中。尝试了很多事情并坚持了这一点
FirebaseUI 不允许您更改用于呈现视图的数据。 这只是开始将数据从Firestore显示到RecyclerView的一种非常简单的方法。 如果您有需要添加或修改查询结果的更高级情况,则需要构建自己的适配器。