I am creating a recycler view in which, I am getting Survey Name which is child of survey reference number in firebase database. What I want is when user click on survey name in recyclerview list it gets the parent KeyValue (which is survey reference number). I have attached the image of the database. On click survey name encircled which blue line, I want the parent key shaded with yellow line
I have used an Interface in adapter class where I am getting position and modelResponse
public SurveysListAdapter(List<SurveysListModel> modelList, Context context, HandleClickListener handleClickListener)
{
this.modelList = modelList;
this.context = context;
this.handleClickListener = handleClickListener;
}
@Override
public void onBindViewHolder(@NonNull final SurveyListViewHolder holder, final int position) {
final SurveysListModel response = modelList.get(position);
holder.questions.setText(response.getSurvey_name());
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
handleClickListener.onItemClicked(position, modelList.get(position));
}
});
}
public interface HandleClickListener {
void onItemClicked(int position, SurveysListModel surveysListModel);
}
Then in Activity Iam getting it like this
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (final DataSnapshot parentSnap : dataSnapshot.getChildren()) {
if (parentSnap.exists()) {
progressDialog.dismiss();
SurveysListModel model = parentSnap.getValue(SurveysListModel.class);
list.add(model);
adapter = new SurveysListAdapter(list, UserAllSurveys.this, new SurveysListAdapter.HandleClickListener() {
@Override
public void onItemClicked(int position, SurveysListModel surveysListModel) {
String typ = surveysListModel.getSurvey_name();
Toast.makeText(UserAllSurveys.this, "CLicked" + position, Toast.LENGTH_SHORT).show();
}
});
recyclerView.setAdapter(adapter);
}