I am trying to access the Key through which my post information is stored in firebase. All I need is to access the Key like we do by using the library.
final String TheKey = getRef(position).getkey();
How can I do the above code while I am using custom RecyclerView How can I access the key as above code does? The problem is I am using Custom RecyclerView that doesn't support getRef()
. I want to access the key inside onBindViewHolder
, where can I get the key below is my code.
@Override
public void onBindViewHolder(@NonNull final viewHolder holder, final int position) {
final String kkk = List.get(position).getUid();
Posts posts = List.get(position);
Picasso.get().load(posts.getPostimage()).placeholder(R.drawable.photo).into(holder.PostImage);
Picasso.get().load(posts.getProfileimage()).fit().into(holder.PostProfileimage);
holder.PostUserName.setText(posts.getFullname());
holder.PostDate.setText(posts.getDate());
holder.PostTime.setText(posts.getTime());
holder.PostDescription.setText(posts.getDescription());
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PostsKey = FirebaseDatabase.getInstance().getReference().child("Posts");
final int postposition = position;
Toast.makeText(context, "User Clicked at Position "+postposition, Toast.LENGTH_SHORT).show();
// Toast.makeText(context, ""+kkk, Toast.LENGTH_SHORT).show();
final String theKey = PostsKey.getRef().getKey();
Toast.makeText(context, ""+theKey, Toast.LENGTH_SHORT).show();
}
});
}