Reputation: 581
I implemented a RecyclerView which is populating some records It is populating appointments and appointments have approved and not approved status.
I implemented an approved button so that onclick the approved status for that appointment is updated on the database and also icon and text is changed of that particular displayed record.
but for some reason in onclick when i am updating the text and icon it is not changing dynamically, but the request to database is working since i can see the change in database, and when i reload the whole data set it shows the changes appropriately.
Here is the code
@Override
public void onBindViewHolder(final AppointmentsHolder holder, final int position) {
final AppointmentObject appointment = appointmentList.get(position);
//binding the data with the viewholder views
holder.patient_name.setText(appointment.patient_name);
holder.app_date.setText(appointment.appointment_date);
if (appointment.descr.length() > 30){
holder.app_descr.setText(String.valueOf(appointment.descr.substring(0,30)));
}else {
holder.app_descr.setText(String.valueOf(appointment.descr));
}
if (appointment.approved_status.equals("0")){
holder.approved_status.setTextColor(Color.RED);
holder.approved_status.setText("Not Approved");
holder.app_pa_approve.setImageResource(R.mipmap.approveicon);
}else {
holder.app_pa_approve.setImageResource(R.mipmap.approvedicon);
holder.approved_status.setTextColor(Color.GREEN);
holder.approved_status.setText("Approved");
}
holder.app_pa_relative.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mOnClickListenr.clicked_On_appointment(appointment);
}
});
holder.app_pa_approve.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
holder.approved_status.setTextColor(Color.GREEN);
holder.approved_status.setText("Approved");
holder.app_pa_approve.setImageResource(R.mipmap.approvedicon);
notifyDataSetChanged();
mOnClickListenr.aprove_appointment(appointment, position);
}
});
}
Here is the onBindViewHolder where i am trying to change the data dynamically onclick.
mOnclickListiner.aprove.appointment is just a listiner which i am implementing in the activity to pass data to activity
public interface OnClickListener{
public void clicked_On_appointment(AppointmentObject appointment);
public void aprove_appointment(AppointmentObject appointment, int position);
}
The mOnClickListenr.aprove_appointment(appointment, position);
inside the OnClcick is executing so i know that the setText and setImageResource are executing as well but for some reason change in not showing in the view.
As you can see i am using notifyDataSetChanged();
properly.
What might be the cause of this behavior ?
As you can see even when i am clicking on the imageButton no dynamic change
only when i reload the arraylist it shows the changed, which means change is happening in database and onclick is executing
Upvotes: 0
Views: 943
Reputation: 2430
You have to set approved on the appointment
When you call notifiyDataSetChanged
it is rebinding all the views and the appointment is still marked unapproved
holder.app_pa_approve.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
appointment.setApprovedStatus(1);
holder.approved_status.setTextColor(Color.GREEN);
holder.approved_status.setText("Approved");
holder.app_pa_approve.setImageResource(R.mipmap.approvedicon);
notifyDataSetChanged();
mOnClickListenr.aprove_appointment(appointment, position);
}
});
Upvotes: 1