我的适配器类
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);
}
}
});
}
}
}
我无法在recyclerview项目之间添加广告,因为有简单的适配器教程,但找不到FirebaseUI Recyclerview适配器的教程。
我已经尝试了google codelab教程,但卡在getItemViewType。尝试了许多事情,并卡在这个
FirebaseUI不允许你改变用于渲染视图的数据。 它只是一个非常简单的方式来开始将数据从Firestore显示到RecyclerView中。 如果你有更高级的情况,需要添加或修改查询结果,你将需要建立自己的适配器。