I am using a FirestoreRecyclerAdapter
.
I'm able to get each model and attributes of documents. But I want to get the document id.
I tried using model.
Autosuggestions, but there was no document id or name
I have the following DealsHolder class. This is in Kotlin. However the rest of all the classes are in java.
package com.guidoapps.firestorerecycleradaptersample
import com.google.firebase.firestore.IgnoreExtraProperties
@IgnoreExtraProperties
data class DealsResponse(var title:String? = null,
var price:String? = null,
var dealPrice:String? = null,
var image:String? = null,
var description: String? = null)
The following function which I initialize in onCreate()
private void getDealsList(){
Query query = db.collection("deals").orderBy("dateTime", Query.Direction.DESCENDING);
FirestoreRecyclerOptions<DealsResponse> response = new FirestoreRecyclerOptions.Builder<DealsResponse>()
.setQuery(query, DealsResponse.class)
.build();
adapter = new FirestoreRecyclerAdapter<DealsResponse, MainActivity.DealsHolder>(response) {
@Override
public void onBindViewHolder(MainActivity.DealsHolder holder, int position, DealsResponse model) {
progressBar.setVisibility(View.GONE);
holder.textTitle.setText(model.getTitle());
holder.textPrice.setText(model.getPrice());
holder.textDesc.setText(model.getDescription());
holder.textDealPrice.setText(model.getDealPrice());
holder.textPrice.setPaintFlags(holder.textPrice.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
Glide.with(getApplicationContext())
.load(model.getImage())
.into(holder.imageView);
holder.itemView.setOnClickListener(v -> {
Snackbar.make(DealsList, model.getTitle(), Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
});
}
Here in the holder.itemView onClickListener I want to get document ID in order to pass to another activity
Then the following DealsHolder.
public class DealsHolder extends RecyclerView.ViewHolder {
@BindView(R.id.title)
TextView textTitle;
@BindView(R.id.thumbnail)
ImageView imageView;
@BindView(R.id.description)
TextView textDesc;
@BindView(R.id.price)
TextView textPrice;
@BindView(R.id.dealPrice)
TextView textDealPrice;
public DealsHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
}