我正在Kotlin中开发一个应用程序,并且正在使用依赖项GraphView。但是,他们的大多数代码都是用Java编写的,将它们转换为Kotlin时遇到了一些麻烦。有人知道这段Java代码相当于Kotlin吗?
GraphView graph = (GraphView) findViewById(R.id.graph);
LineGraphSeries<DataPoint> series = new LineGraphSeries<DataPoint>(new DataPoint[] {
new DataPoint(0, 1),
new DataPoint(1, 5),
new DataPoint(2, 3),
new DataPoint(3, 2),
new DataPoint(4, 6)
});
graph.addSeries(series);
答案 0 :(得分:1)
val graph = findViewById(R.id.graph) as GraphView
val series = LineGraphSeries(arrayOf(
DataPoint(0, 1),
DataPoint(1, 5),
DataPoint(2, 3),
DataPoint(3, 2),
DataPoint(4, 6)
)
)
graph.addSeries(series)
但是您可以订购
val graph: GraphView = findViewById(R.id.graph)
graph.addSeries(LineGraphSeries(arrayOf(
DataPoint(0, 1),
DataPoint(1, 5),
DataPoint(2, 3),
DataPoint(3, 2),
DataPoint(4, 6)
)
))