I am a newbie in android studio. I want to know how many times "plastic" appears in the Firebase Document field. And show it in MPChart. I count 'Plastic' in Firebase Connect, but it can't work in data().How can I write Plastic?
public class MainChart {
BarChart barChart;
int Plastic;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.chart);
getMultipleDocs();
BarData barData = new BarData();
barData.addDataSet(barDataSet);
barChart.setData(barData);
barChart.invalidate();
}
public void getMultipleDocs() {
.collection("Garbage")
.whereEqualTo("name","plastic")
.get()
.addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
List<DocumentSnapshot> snapshotList = queryDocumentSnapshots.getDocuments();
for(DocumentSnapshot snapshot:snapshotList){
Log.d(TAG, "onSuccess: "+snapshot.getData().toString());
}
Plastic++;
Log.d(getClass().getName(), "plastic have = " + Plastic);
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e(TAG, "onFailure: ", e);
}
});
public ArrayList<BarEntry> data(){
ArrayList<BarEntry> dataVal = new ArrayList<>();
dataVal.add(new BarEntry(0,Plastic));
return dataVal;
}
}