skip to Main Content

I am using firebase recycler options to retrieve data needed from firebase database, which in this case 3 boolean value. In the adapter, i found out that all boolean value retrieved is false. However, when i start the activity and select the spinner, the spinner correctly set up the boolean value in firebase database. Moreover, the selection on the spinner not set correctly according to the data, as it retrieve all false in the database.

I attached my helper class, adapter onbindviewholder and onitemselected.

BookingModal.class

public class BookingModal {

    private String DATE;
    private String TIME;
    private String UID;
    private boolean approved;
    private boolean pending;
    private boolean rejected;

    public BookingModal(String DATE, String TIME, String UID, boolean approved, boolean pending, boolean rejected) {
        this.DATE = DATE;
        this.TIME = TIME;
        this.UID = UID;
        this.approved = approved;
        this.pending = pending;
        this.rejected = rejected;
    }
    public BookingModal(){}

    public String getDATE() {
        return DATE;
    }

    public void setDATE(String DATE) {
        this.DATE = DATE;
    }

    public String getTIME() {
        return TIME;
    }

    public void setTIME(String TIME) {
        this.TIME = TIME;
    }

    public String getUID() {
        return UID;
    }

    public void setUID(String UID) {
        this.UID = UID;
    }


    public boolean Approved() {
        return approved;
    }

    public void setApproved(boolean approved) {
        this.approved = approved;
    }

    public boolean Pending() {
        return pending;
    }

    public void setPending(boolean pending) {
        this.pending = pending;
    }

    public boolean Rejected() {
        return rejected;
    }

    public void setRejected(boolean rejected) {
        this.rejected = rejected;
    }
}

Adapter onbindviewholder class.

  @Override
    protected void onBindViewHolder(@NonNull BookingVH holder, int position, @NonNull BookingModal model) {

        holder.date.setText(model.getDATE());

        UserModal userModalDetail = findbyProperty(userModalList, model.getUID());
        if (userModalDetail != null) {
            holder.name.setText(userModalDetail.getName());
            holder.matric.setText(userModalDetail.getMatricnumber());
            onStatusSelected.onSelected(holder.status, userModalDetail.getUID(), model);
        }

        Log.d("booleanvalue", model.Pending() + " - "+model.Approved()+" - "+model.Rejected());



    }

onitemselected for spinner

 @Override
    public void onSelected(Spinner v, String uid, BookingModal modal) {
        Log.d("modalboolean", String.valueOf(modal.Approved()));
        v.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                checker.clear();
                if (i == 0){
                    mDatabase.child("Bookings").child("Kompleks Sukan A").child("Pending").child(uid).child("isPending").setValue(true);
                    mDatabase.child("Bookings").child("Kompleks Sukan A").child("Pending").child(uid).child("isApproved").setValue(false);
                    mDatabase.child("Bookings").child("Kompleks Sukan A").child("Pending").child(uid).child("isRejected").setValue(false);

                } else if (i == 1){
                    mDatabase.child("Bookings").child("Kompleks Sukan A").child("Pending").child(uid).child("isApproved").setValue(true);
                    mDatabase.child("Bookings").child("Kompleks Sukan A").child("Pending").child(uid).child("isPending").setValue(false);
                    mDatabase.child("Bookings").child("Kompleks Sukan A").child("Pending").child(uid).child("isRejected").setValue(false);


                } else if (i == 2){
                    mDatabase.child("Bookings").child("Kompleks Sukan A").child("Pending").child(uid).child("isRejected").setValue(true);
                    mDatabase.child("Bookings").child("Kompleks Sukan A").child("Pending").child(uid).child("isApproved").setValue(false);
                    mDatabase.child("Bookings").child("Kompleks Sukan A").child("Pending").child(uid).child("isPending").setValue(false);

                }
                v.setSelection(i, true);

                Log.d("CheckerMap", checker.toString());
//                mDatabase.child("Bookings").child("Kompleks Sukan A").child("Pending").child(uid).updateChildren(checker);
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {

            }
        });
    }

Really appreciate for any help. Thank you in advance !

EDITED

Here is my json db structure

{
  "Admin": {
    "e7oK2kaWLDW5SdSnBS1KEKXazNH3": {
      "admin": true,
      "departmentnumber": "",
      "email": "[email protected]",
      "matricnumber": "",
      "name": "admin1",
      "password": "admin123",
      "phonenumber": ""
    }
  },
  "Bookings": {
    "Kompleks Sukan A": {
      "Pending": {
        "AQ7W0xjc0kYZTg7mz5LH8m7wAXF3": {
          "DATE": "19/01/2023",
          "TIME": "1-2PM",
          "UID": "AQ7W0xjc0kYZTg7mz5LH8m7wAXF3",
          "isApproved": true,
          "isPending": false,
          "isRejected": false
        },
        "a59Pmpt9kvNTO6yFjXspGRqmlGh1": {
          "date": "26/01/2023",
          "isApproved": false,
          "isPending": false,
          "isRejected": true,
          "time": "1-2PM",
          "uid": "a59Pmpt9kvNTO6yFjXspGRqmlGh1"
        }
      }
    }
  },
  "Kompleks Sukan A": {
    "1-2PM": false,
    "10-11AM": false,
    "11-12PM": false,
    "12-1PM": false,
    "2-3PM": false,
    "3-4PM": false,
    "4-5PM": false,
    "5-6PM": false,
    "6-7PM": false,
    "9-10AM": false
  },
  "Users": {
    "AQ7W0xjc0kYZTg7mz5LH8m7wAXF3": {
      "admin": false,
      "departmentnumber": "",
      "email": "[email protected]",
      "matricnumber": "",
      "name": "test",
      "password": "user123",
      "phonenumber": "",
      "uid": "AQ7W0xjc0kYZTg7mz5LH8m7wAXF3"
    },
    "a59Pmpt9kvNTO6yFjXspGRqmlGh1": {
      "admin": false,
      "departmentnumber": "",
      "email": "[email protected]",
      "matricnumber": "53104119052",
      "name": "ceyn",
      "password": "ceyn123",
      "phonenumber": "01112872692",
      "uid": "a59Pmpt9kvNTO6yFjXspGRqmlGh1"
    }
  }
}

2

Answers


  1. Chosen as BEST ANSWER

    I ended up using a single string as status checking. Changing it easier to use with spinner.


  2. In your POJO classes, you have declared

    private boolean approved;
    private boolean pending;
    private boolean rejected;
    

    while generating build, android change variable names of boolean types.

    To prevent this changing, you can keep your model classes in Proguard Rules as follow:

    -keep class com.example.myapplication.models.**
    

    keep all of your classes under models package. Now it will not change the names of variables.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search