如何将Firestore文档ID放入RecyclerView适配器?

时间:2020-05-30 16:34:35

标签: java android firebase google-cloud-firestore

我想将Firestore文档ID调用到RecyclerView适配器中。但没有得到该怎么做。有人可以帮忙吗实际上,我想使用纸质DB在我的应用程序中添加fab功能。所以我希望使用文档ID进行操作,因为它对于每个文档都是唯一的。但没有获得将文档ID放入适配器类的方法,这样我就可以使用它。

Firestore结构图片。

Firestore Image

我的适配器类:

for

家庭片段:

public class CitiesAdapter extends RecyclerView.Adapter<CitiesAdapter.ViewHolder> {

    public List<Cities> citiesList;

    public CitiesAdapter(Context context, List<Cities> citiesList) {
        this.citiesList = citiesList;
    }

    @Override
    public int getItemCount() {
        return citiesList.size();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View citiesView = LayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_cities_you_must_visit, parent, false);
        return new ViewHolder(citiesView);
    }

    @Override
    public void onBindViewHolder(final CitiesAdapter.ViewHolder holder, final int position) {

            holder.vCityName.setText(citiesList.get(position).getmCityName() + ",");

    public class ViewHolder extends RecyclerView.ViewHolder {

        public TextView vCityName;

        View CityView;


        public ViewHolder(View itemView) {
            super(itemView);
            CityView = itemView;

            vCityName = CityView.findViewById(R.id.lCityName);

        }
    }

}

0 个答案:

没有答案