package com.example.nameofyourproject; //Change this to the name of your project import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.widget.TextView; import com.google.firebase.database.ChildEventListener; import com.google.firebase.database.DataSnapshot; import com.google.firebase.database.DatabaseError; import com.google.firebase.database.DatabaseReference; import com.google.firebase.database.FirebaseDatabase; import com.google.firebase.database.ValueEventListener; public class MainActivity extends AppCompatActivity { private TextView mTemperatureTextView; private TextView mHumidityTextView; private FirebaseDatabase mFirebaseDatabase; private DatabaseReference mMessagesDatabaseReference; private ChildEventListener mChildEventListener; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTemperatureTextView = (TextView) findViewById(R.id.number2); mHumidityTextView = (TextView) findViewById(R.id.number); mFirebaseDatabase = FirebaseDatabase.getInstance(); mMessagesDatabaseReference = mFirebaseDatabase.getReference(); mMessagesDatabaseReference.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(@NonNull DataSnapshot dataSnapshot) { String humidity = dataSnapshot.child("Humidity").getValue().toString(); String temperature = dataSnapshot.child("Temp").getValue().toString(); mTemperatureTextView.setText(temperature+" C"); mHumidityTextView.setText(humidity+" %"); } @Override public void onCancelled(@NonNull DatabaseError databaseError) { } }); } }