title: Firebase ArrayList with buttons update firebase data
body: <p>I'm creating an appointment management system for students and lecturers. I have an array listview which retrieves data from firebase. I included two buttons to change the status of the appointment to accepted or rejected. I could not find a code to update the firebase data on the listview when the buttons are pressed. </p>
  
  <p>I'm actually new to android development so forgive me if I ask questions that are easy to answer. I've tried everything to find a solution to my problem but i can't seem to find one. This is an appointment management system where students could set up an appointment with their lecturers. For the lecturer view, I have a listview which shows all the request for an appointment made by students. Each row will have 2 sets of buttons which is to accept or reject the appointment. When either one of the buttons is pressed, it will update the status of the appointment eg; press approve button status turns to approved. The data is retrieved from the firebase real-time database.  My problem is that I could not find an appropriate code to update the status of the appointment when either the two buttons are pressed. I really need help for this. Thanks in advance. </p>
  
  <p>This is for my activity.</p>
  
  <pre><code>public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
      v = inflater.inflate(R.layout.lect_fragment_appointment, container, false);
  
      myrecyclerview= (RecyclerView)  v.findViewById(R.id.appointment_list_recyclerview2);
      myrecyclerview.setLayoutManager(new LinearLayoutManager(getActivity()));
      list = new ArrayList&lt;ListView_Appointmnet_LectView&gt;();
  
      SharedPreferences preferences = this.getActivity().getSharedPreferences("user_details", Context.MODE_PRIVATE);
  
      databaseReference = FirebaseDatabase.getInstance().getReference().child("Appointment");
  
  
      Query query1 = databaseReference.orderByChild("lect_name").equalTo(preferences.getString("Lect_Name",null));
  
  
  
      query1.addValueEventListener(new ValueEventListener() {
          @Override
          public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
              for (DataSnapshot dataSnapshot1: dataSnapshot.getChildren())
              {
  
                  ListView_Appointmnet_LectView L = dataSnapshot1.getValue(ListView_Appointmnet_LectView.class);
                  list.add(L);
  
              }
  
              adapter = new CustomAdapter_ListView_Lecturer(getContext(),list);
              myrecyclerview.setAdapter(adapter);
              adapter.notifyDataSetChanged();
  </code></pre>
  
  <p>}</p>
  
  <p>This is my adapter view</p>
  
  <pre><code>public class CustomAdapter_ListView_Lecturer extends RecyclerView.Adapter&lt;CustomAdapter_ListView_Lecturer.MyViewHolder&gt; {
  
  Context context;
  
  ArrayList &lt;ListView_Appointmnet_LectView&gt; appointment_lectview ;
  
  public CustomAdapter_ListView_Lecturer(Context c, ArrayList&lt;ListView_Appointmnet_LectView&gt; a)
  {
      context = c;
      appointment_lectview = a;
  }
  
  @NonNull
  @Override
  public MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
      return new MyViewHolder(LayoutInflater.from(context).inflate(R.layout.item_appointment_list_lecturer, viewGroup, false));
  }
  
  @Override
  public void onBindViewHolder(@NonNull MyViewHolder myViewHolder, int position) {
  
      myViewHolder.name.setText(appointment_lectview.get(position).getStudent_ID());
      myViewHolder.subject.setText(appointment_lectview.get(position).getSubject());
      myViewHolder.date.setText(appointment_lectview.get(position).getStart_date());
      myViewHolder.time.setText(appointment_lectview.get(position).getStart_time());
      myViewHolder.onClick(position);
  
  
  
  }
  
  @Override
  public int getItemCount() {
      return appointment_lectview.size();
  }
  
  class MyViewHolder extends RecyclerView.ViewHolder {
  
      TextView name, date, subject, time, status;
      ImageButton approve_btn, reject_btn;
  
  
      public MyViewHolder(@NonNull View itemView) {
          super(itemView);
          name = (TextView) itemView.findViewById(R.id.appointment_studentID);
          date = (TextView) itemView.findViewById(R.id.appointment_date);
          subject = (TextView) itemView.findViewById(R.id.appointment_subject);
          time = (TextView) itemView.findViewById(R.id.appointment_time);
          status = (TextView) itemView.findViewById(R.id.appointment_status);
          approve_btn = (ImageButton) itemView.findViewById(R.id.approve_btn);
          reject_btn = (ImageButton) itemView.findViewById(R.id.reject_btn);
      }
  
      public void onClick(final int position) {
          approve_btn.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Toast.makeText(context, "Approve " + position + "is clicked", Toast.LENGTH_SHORT).show();
  
  
              }
          });
  
          reject_btn.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Toast.makeText(context, "Reject " + position + "is clicked", Toast.LENGTH_SHORT).show();
  
              }
          });
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Setter and getter class:</p>
  
  <pre><code>public class ListView_Appointmnet_LectView {
  
  private String start_date;
  private String subject;
  private String start_time;
  private String student_ID;
  private String status;
  
  
  public ListView_Appointmnet_LectView() {
  
  }
  
  public ListView_Appointmnet_LectView(String start_date, String subject, String start_time, String student_ID, String status) {
      this.start_date = start_date;
      this.subject = subject;
      this.start_time = start_time;
      this.student_ID = student_ID;
      this.status = status;
  }
  
  public String getStart_date() {
      return start_date;
  }
  
  public void setStart_date(String start_date) {
      this.start_date = start_date;
  }
  
  public String getSubject() {
      return subject;
  }
  
  public void setSubject(String subject) {
      this.subject = subject;
  }
  
  public String getStart_time() {
      return start_time;
  }
  
  public void setStart_time(String start_time) {
      this.start_time = start_time;
  }
  
  public String getStudent_ID() {
      return student_ID;
  }
  
  public void setStudent_ID(String student_ID) {
      this.student_ID = student_ID;
  }
  
  public String getStatus() {
      return status;
  }
  
  public void setStatus(String status) {
      this.status = status;
  }
  </code></pre>
  
  <p>}</p>