Solution 1 :
You’ll need to store the ID/Key of each item that you display in the recycler view, when you also get its value from the database.
So when you add the value to duyuruArrayList
, you also need to store the ID/key from the database, either in the same list, or in a list with the same order.
You can then look up the ID/key in the same way as you now look up the value in duyuruArrayList
, by its position, and update the item in the database with that.
Problem :
I am trying to do when i click the recyclerView item, i can update that item.But that items connected to Firebase Database so first of all i have to get the id from clicked item which i can, but i am getting the latest added recyclerView item id. I want to get each RecyclerView item id from Firebase when i click. So i can update them.
Note:Pid is my database ids.
My RecyclerAdapter:
private ArrayList<Duyuru> duyuruArrayList;
public void onBindViewHolder(@NonNull ViewHolder holder, final int position) {
holder.txtBaslik.setText(duyuruArrayList.get(position).getDuyuruBaslik());
holder.txtContext.setText(duyuruArrayList.get(position).getDuyuruContext());
holder.txtYazar.setText(duyuruArrayList.get(position).getDuyuruYazar());
holder.txtTime.setText(duyuruArrayList.get(position).getDuyuruTime());
holder.txtDate.setText(duyuruArrayList.get(position).getDuyuruDate());
holder.parentLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(mContext, activity_duyuru_update_screen.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("baslik",duyuruArrayList.get(position).getDuyuruBaslik());
intent.putExtra("context",duyuruArrayList.get(position).getDuyuruContext());
intent.putExtra("yazar",duyuruArrayList.get(position).getDuyuruYazar());
intent.putExtra("time",duyuruArrayList.get(position).getDuyuruTime());
intent.putExtra("date",duyuruArrayList.get(position).getDuyuruDate());
intent.putExtra("pid",duyuruArrayList.get(position).getPid());
mContext.startActivity(intent);
}
});
}