public void getOmikuji(View view) {
// TextViewの取得
TextView tv = (TextView) findViewById(R.id.myTextView);
String[] results = {
"大吉",
"吉",
"凶"
};
// 乱数の生成
Random randomGenerator = new Random();
int num = randomGenerator.nextInt(results.length); // 0-2
// 結果の表示
// String result = Integer.toString(num);
tv.setText(results[num]);
}
テーマの変更
rsc -> values -> styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
activity_main.xmlはstrings.xmlへの記載することが推奨されています。
rsc -> values -> strings.xml
<resources>
<string name="app_name">おみくじアプリ</string>
<string name="omikuji_label">あなたの運勢は...</string>
<string name="score_label">____</string>
<string name="button_label">おみくじを引く</string>
</resources>