質問編集履歴
1
コード追加と文章追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
現在AndroidStudioで診断系のアプリを制作しています。そこで出題問題ごとにボタンのテキストも変更したいと思い以下のプログラムを組みました。理想は問題の乱数rにあわせてボタンのテキストビューが変わるようにしたいのですが、次の問題が表示されても次の問題用の回答用にボタンのテキストが変わってくれません。どうすればよいかアドバイスをいただきたいと思い投稿しました。よろしくお願いいたします
|
1
|
+
現在AndroidStudioで診断系のアプリを制作しています。そこで出題問題ごとにボタンのテキストも変更したいと思い以下のプログラムを組みました。理想は問題の乱数rにあわせてボタンのテキストビューが変わるようにしたいのですが、次の問題が表示されても次の問題用の回答用にボタンのテキストが変わってくれません。どうすればよいかアドバイスをいただきたいと思い投稿しました。よろしくお願いいたします。追記7/19、一応ボタンを押した際にボタンのテキストを変えることができました(二個目のコード参照)ただほかにも良いやり方がありそうなので回答を待っています。こうすればもう少しスタイリッシュでシンプルなコードになるよって意見がありましたぜひお願いします。
|
2
2
|
```ここに言語を入力
|
3
3
|
コード
|
4
4
|
public class shindan extends AppCompatActivity {
|
@@ -68,4 +68,49 @@
|
|
68
68
|
}
|
69
69
|
|
70
70
|
}
|
71
|
+
|
72
|
+
```
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
```ここに言語を入力
|
78
|
+
コード
|
79
|
+
public void onTop(View view) {//上のボタンのメソッド
|
80
|
+
count--;
|
81
|
+
if (count > 0) {
|
82
|
+
((TextView) findViewById(R.id.tc)).setText("のこり" + count + "問...");
|
83
|
+
//出題
|
84
|
+
r = new Random().nextInt(q.length);
|
85
|
+
((TextView) findViewById(R.id.situmon)).setText(q[r]);
|
86
|
+
|
87
|
+
|
88
|
+
if (r == 0) {//ここにテキストを変えるメソッド追加
|
89
|
+
((TextView) findViewById(R.id.top)).setText(ta[0]);
|
90
|
+
((TextView) findViewById(R.id.bottom)).setText(ba[0]);
|
91
|
+
}else if (r==1){
|
92
|
+
((TextView) findViewById(R.id.top)).setText(ta[1]);
|
93
|
+
((TextView) findViewById(R.id.bottom)).setText(ba[1]);
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
}
|
98
|
+
public void onBottom (View view){//下のボタンのメソッド
|
99
|
+
count--;
|
100
|
+
if (count > 0) {
|
101
|
+
((TextView) findViewById(R.id.tc)).setText("のこり" + count + "問...");
|
102
|
+
//出題
|
103
|
+
r = new Random().nextInt(q.length);
|
104
|
+
((TextView) findViewById(R.id.situmon)).setText(q[r]);
|
105
|
+
|
106
|
+
|
107
|
+
if (r == 0) {//ここにテキストを変えるメソッド追加
|
108
|
+
((TextView) findViewById(R.id.top)).setText(ta[0]);
|
109
|
+
((TextView) findViewById(R.id.bottom)).setText(ba[0]);
|
110
|
+
}else if (r==1){
|
111
|
+
((TextView) findViewById(R.id.top)).setText(ta[1]);
|
112
|
+
((TextView) findViewById(R.id.bottom)).setText(ba[1]);
|
113
|
+
}
|
114
|
+
}
|
115
|
+
}
|
71
116
|
```
|