I am a beginner in programming and I'm trying to retrieve these data sent by raspberry pi from Arduino. What do you think is the problem?
!Firebase Database Image I've tried multiple tutorial videos and the answers on similar problems on this site but I still can't retrieve the data.
This is the current code:
public class ph extends AppCompatActivity {
ArrayList <String> list;
ArrayAdapter <String> adapter;
phlevel phlvl;
private static final String TAG = "phlevel";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ph);
phlvl = new phlevel();
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference mRef = database.getReference("phlevel");
final ListView mListView = (ListView) findViewById(R.id.listView);
list = new ArrayList<>();
adapter = new ArrayAdapter<String>(this,R.layout.activity_ph,R.id.phlevelinfo,list);
mRef.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
}
@Override
public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
{
if(dataSnapshot.child("date").exists() &&
dataSnapshot.child("time").exists() &&
dataSnapshot.child("value").exists()) {
Log.d(TAG,"onChildChanged: " + dataSnapshot.toString());
}
}
This is the phlevel code:
public class phlevel {
private String date;
private String time;
private String value;
public phlevel(String date, String time, String value) {
this.date = date;
this.time = time;
this.value = value;
}
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 getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
And this is the XML for the ph activity:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ph">
<TextView
android:id="@+id/phlevelinfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:text="Displaying pH Level"
android:textSize="30sp"
tools:ignore="HardcodedText" />
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="30dp" />
</LinearLayout>
I am expecting that the values in "date, time, and value" from the database be retrieved and listed on ListView. Instead, the app shows nothing except the text "Displaying pH Level". Thank you.