ことりん
いまさらですが、Androidアプリの開発言語にKotlinが正式採用されましたね。
検索するとすごくいいらしいので、これからの開発はKotlinでやっていこうと思います。
なので、最近ぼちぼち勉強中です。
試しに以下の記事を参考に(ほぼコピペ)、ストップウォッチアプリを作りました。
employment.en-japan.com
私の環境ではこのままでは動かず、以下のように修正しました。
修正前
// View要素を変数に代入 val timeText = findViewById(R.id.timeText) as TextView val startButton = findViewById(R.id.start) as Button val stopButton = findViewById(R.id.stop) as Button val resetButton = findViewById(R.id.reset) as Button
修正後
// View要素を変数に代入 val timeText = findViewById<TextView>(R.id.timeText) val startButton = findViewById<Button>(R.id.start) val stopButton = findViewById<Button>(R.id.stop) val resetButton = findViewById<Button>(R.id.reset)
修正後は記事の通りに動いています。
一応、githubにupしました。これを元に何か作っても面白そう。