I want to display the firebase data into the custom recyclerview. The data is added to the firebase from the arduino which i want to display in the app itself.
i am trying to run the following code but the app simply opens and doesnt display anything. Each time the app runs on the android, it opens and doesnt diaplay anything. The same code is working with my other 2-3 projects but doesnt seem to work in this case.
1.MainActivity.java
public class MainActivity extends AppCompatActivity {
private RecyclerView recyclerView;
private DatabaseReference myref;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerView = findViewById(R.id.mango);
myref = FirebaseDatabase.getInstance().getReference().child("database").child("values");
FirebaseRecyclerAdapter<valueretriever, ProgramViewHolder> recyclerAdapter = new FirebaseRecyclerAdapter<valueretriever, ProgramViewHolder>(
valueretriever.class,
R.layout.individual_row,
ProgramViewHolder.class,
myref
) {
@Override
protected void populateViewHolder(ProgramViewHolder viewHolder, valueretriever model, int position) {
viewHolder.setMoisture(model.getMoisture());
viewHolder.setMotor_time(model.getMotortime());
viewHolder.setPower(model.getPower());
}
};
recyclerView.setAdapter(recyclerAdapter);
}
public static class ProgramViewHolder extends RecyclerView.ViewHolder {
View mView;
TextView txtmoisture;
TextView txtmotor_time;
TextView txtpower;
String moisturee, motortimee, powerr;
public ProgramViewHolder(View itemView) {
super(itemView);
mView = itemView;
txtmoisture = itemView.findViewById(R.id.textview1);
txtmotor_time = itemView.findViewById(R.id.textview2);
txtpower = itemView.findViewById(R.id.textview3);
}
public void setMoisture(String moisture) {
txtmoisture.setText(moisture);
moisturee = txtmoisture.getText().toString();
}
public void setMotor_time(String motor_time) {
txtmotor_time.setText(motor_time);
motortimee = txtmotor_time.getText().toString();
}
public void setPower(String power) {
txtpower.setText(power);
powerr = txtpower.getText().toString();
}
}
}
2.activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.v7.widget.RecyclerView
android:id="@+id/mango"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
3.valueretriever.java
public class valueretriever {
private String moisture;
private String motor_time;
private String power;
public valueretriever() {
}
public valueretriever(String moisture, String motor_time, String power) {
this.moisture = moisture;
this.motor_time = motor_time;
this.power = power;
}
public String getMoisture() {
return moisture;
}
public void setMoisture(String moisture) {
this.moisture = moisture;
}
public String getMotortime() {
return motor_time;
}
public void setMotortime(String motor_time) {
this.motor_time = motor_time;
}
public String getPower() {
return power;
}
public void setPower(String power) {
this.power = power;
}
}
4.individual_row.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="#282828"
android:orientation="vertical">
<TextView
android:id="@+id/textview1"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_below="@+id/textview2"
android:layout_centerHorizontal="true"
android:gravity="center_vertical"
android:textColor="#ffffff"
android:textSize="50sp" />
<TextView
android:id="@+id/textview2"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:gravity="center_vertical"
android:textColor="#ffffff"
android:textSize="50sp" />
<TextView
android:id="@+id/textview3"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:gravity="center_vertical"
android:textColor="#ffffff"
android:textSize="50sp" />
</RelativeLayout>