Home > Software design >  Retrieving integer datatype from firebase realtime to Android textview
Retrieving integer datatype from firebase realtime to Android textview

Time:08-18

I'm trying to retrieve the integer values from Firebase Realtime to Android Studio textview. But the integer values doesn't show in my textview

HERE IS MY CODE:

 @Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
    if (snapshot.getValue(Integer.class)!=null){

        String key = snapshot.getKey();
        if (key.equals("WaterTemperature")) {

            int first = snapshot.getValue(Integer.class);
            waterTempVal.setText(first);
        }

        if (key.equals("WaterTurbidity")) {

            int second = snapshot.getValue(Integer.class);
            waterTurbidityVal.setText(second);
        }

        if (key.equals("WaterPh")) {

            int third = snapshot.getValue(Integer.class);
            waterPhVal.setText(third);
        }
    }
}

I don't know what I'm doing wrong can someone enlighten me

CodePudding user response:

try this, just convert to toString OR wrapString

int first = snapshot.getValue(Integer.class);
 waterTempVal.setText(first.toString());
  • Related