- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain2Activity.java
More file actions
Latest commit
63 lines (47 loc) · 1.72 KB
/
Copy pathMain2Activity.java
File metadata and controls
63 lines (47 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
packagecom.example.weighttracker;
importandroidx.appcompat.app.AppCompatActivity;
importandroid.database.Cursor;
importandroid.graphics.Color;
importandroid.os.Bundle;
importcom.github.mikephil.charting.charts.BarChart;
importcom.github.mikephil.charting.data.BarData;
importcom.github.mikephil.charting.data.BarDataSet;
importcom.github.mikephil.charting.data.BarEntry;
importcom.github.mikephil.charting.utils.ColorTemplate;
importjava.util.ArrayList;
publicclassMain2ActivityextendsAppCompatActivity {
BarChartbarChart;
BarDatabarData;
BarDataSetbardataSet;
ArrayListbarEntries;
DatabaseHelpermyDb;
@Override
protectedvoidonCreate(BundlesavedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
myDb = newDatabaseHelper(this);
barChart = (BarChart)findViewById(R.id.Barchart);
getEntries();
bardataSet = newBarDataSet(barEntries,"Data Set");
barData = newBarData(bardataSet);
barChart.setData(barData);
bardataSet.setColors(ColorTemplate.MATERIAL_COLORS);
bardataSet.setValueTextColor(Color.BLACK);
bardataSet.setValueTextSize(16f);
}
publicvoidgetEntries(){
barEntries = newArrayList<>();
Cursorcr = myDb.getallData();
if(cr.getCount()==0){
barEntries.add(newBarEntry(0f,0));
}else{
floatf = 1f;
while(cr.moveToNext()){
doubleweight = cr.getDouble(2);
floatm = (float)weight;
barEntries.add(newBarEntry(f,m));
f+=1f;
}
}
}
}