@@ -11,17 +11,17 @@ import android.view.MenuItem
1111import android.view.View
1212import android.view.ViewGroup
1313import android.widget.ArrayAdapter
14+ import androidx.core.net.toUri
15+ import info.appdev.chartexample.DataTools.Companion.getValues
16+ import info.appdev.chartexample.databinding.ActivityListviewChartBinding
17+ import info.appdev.chartexample.notimportant.DemoBase
1418import info.appdev.charting.charts.BarChart
1519import info.appdev.charting.components.XAxis.XAxisPosition
1620import info.appdev.charting.data.BarData
1721import info.appdev.charting.data.BarDataSet
1822import info.appdev.charting.data.BarEntry
1923import info.appdev.charting.interfaces.datasets.IBarDataSet
2024import info.appdev.charting.utils.ColorTemplate
21- import info.appdev.chartexample.DataTools.Companion.getValues
22- import info.appdev.chartexample.notimportant.DemoBase
23- import androidx.core.net.toUri
24- import info.appdev.chartexample.databinding.ActivityListviewChartBinding
2525
2626/* *
2727 * Demonstrates the use of charts inside a ListView. IMPORTANT: provide a
@@ -58,46 +58,44 @@ class ListViewBarChartActivity : DemoBase() {
5858 if (convertView == null ) {
5959 holder = ViewHolder ()
6060
61- convertView = LayoutInflater .from(context).inflate(
62- R .layout.list_item_barchart, null
63- )
61+ convertView = LayoutInflater .from(context).inflate(R .layout.list_item_barchart, null )
6462 holder.chart = convertView.findViewById(R .id.chart)
6563
6664 convertView.tag = holder
6765 } else {
6866 holder = convertView.tag as ViewHolder
6967 }
7068
71- // apply styling
72- if (data != null ) {
73- data.setValueTypeface(tfLight)
74- data.setValueTextColor(Color .BLACK )
75- }
76- holder.chart!! .description?.isEnabled = false
77- holder.chart!! .setDrawGridBackground(false )
69+ data?.setValueTypeface(tfLight)
70+ data?.setValueTextColor(Color .BLACK )
71+ holder.chart?.description?.isEnabled = false
72+ holder.chart?.setDrawGridBackground(false )
73+
7874
79- val xAxis = holder.chart!! .xAxis
80- xAxis.position = XAxisPosition .BOTTOM
81- xAxis.typeface = tfLight
82- xAxis.setDrawGridLines(false )
75+ holder.chart?.xAxis?.apply {
76+ this .position = XAxisPosition .BOTTOM
77+ typeface = tfLight
78+ setDrawGridLines(false )
79+ }
8380
84- val leftAxis = holder.chart!! .axisLeft
85- leftAxis.typeface = tfLight
86- leftAxis.setLabelCount(5 , false )
87- leftAxis.spaceTop = 15f
81+ holder.chart?.axisLeft?.apply {
82+ typeface = tfLight
83+ setLabelCount(5 , false )
84+ spaceTop = 15f
85+ }
8886
89- val rightAxis = holder.chart!! .axisRight
90- rightAxis.typeface = tfLight
91- rightAxis.setLabelCount(5 , false )
92- rightAxis.spaceTop = 15f
87+ holder.chart?.axisRight?.apply {
88+ typeface = tfLight
89+ setLabelCount(5 , false )
90+ spaceTop = 15f
91+ }
9392
94- // set data
95- holder.chart!! .setData(data)
96- holder.chart!! .setFitBars(true )
93+ holder.chart?.setData(data)
94+ holder.chart?.setFitBars(true )
9795
9896 // do not forget to refresh the chart
9997// holder.chart.invalidate();
100- holder.chart!! .animateY(700 )
98+ holder.chart? .animateY(700 )
10199
102100 return convertView
103101 }
@@ -109,8 +107,6 @@ class ListViewBarChartActivity : DemoBase() {
109107
110108 /* *
111109 * generates a random ChartData object with just one DataSet
112- *
113- * @return Bar data
114110 */
115111 private fun generateData (cnt : Int ): BarData {
116112 val count = 12
0 commit comments