我正在使用firebaseUI
使用库来填充回收器视图firestore
数据库。
当我尝试检索时文档编号当我点击回收器查看项目时,它是这样的
DocumentSnapshot snapshot = getSnapshots()
.getSnapshot(holder.getAdapterPosition());
final String countryName = snapshot.getId();
我试过这个代码但是getSnapshots()
出现红色字,但内部不起作用onbindeviewolder
所以我尝试了这个但也不起作用
DocumentReference aa=firebaseFirestore.collection("MainCategories").document(String.valueOf(SS));
String aaa=aa.getId();
那么有没有什么方法可以检索文档ID,因为上面的代码不在这里工作
private class CategoriesAdapter extends RecyclerView.Adapter<AllCategoriesViewHolder> {
private List<mainCategroies> categorylist;
CategoriesAdapter(List<mainCategroies> categorylist) {
this.categorylist = categorylist;
}
@NonNull
@Override
public AllCategoriesViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_maincategory, parent, false);
return new AllCategoriesViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull final AllCategoriesViewHolder holder, int position) {
final String categoryName = categorylist.get(position).getCategory_Name();
holder.setCategory_Name(categoryName);
String d = categorylist.get(position).getImageUrl();
holder.setImageUrl(d);
MainActivityProgress.setVisibility(View.GONE);
holder.view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
}
@Override
public int getItemCount() {
return categorylist.size();
}
}
持有者阶层
私有类 AllCategoriesViewHolder 扩展 RecyclerView.ViewHolder {
私人景观;
public AllCategoriesViewHolder(final View itemView) {
super(itemView);
view = itemView;
}
void setCategory_Name(String category_Name) {
TextView names = view.findViewById(R.id.CategoryName);
names.setText(category_Name);
}
void setImageUrl(String imageUrl) {
ImageView imageView = view.findViewById(R.id.MainCat_CardViewImage);
Picasso.get()
.load(imageUrl)
.fit()
.into(imageView);
}
}
和模型类
public class CountryItem {
private String CountryName;
public CountryItem(){
}
public CountryItem(String countryName) {
CountryName = countryName;
}
public String getCountryName() {
return CountryName;
}
public void setCountryName(String countryName) {
CountryName = countryName;
}
}