回答編集履歴
4
追記
answer
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
[画面遷移の課題、numPickerとEditTextbuttonの対応について](https://teratail.com/questions/248448) で不足でしたら, そちらに追加してください.
|
|
2
|
+
ただ, 回答したコードはやり過ぎた感はありますので, 今夜修正しておきます.
|
|
2
3
|
|
|
3
4
|
レイアウトに配置した 36 個のボタンの id を配列に入れておき(仮に ```int[] buttons = new int[]{ R.id.button1, R.id.button2, ..., R.id.button36 };``` ), numPicker をそのインデックス ( buttons[numPicker-1] ← numPicker は1始まり, 配列は0始まりなので-1している) とすれば該当のボタンの id が得られます.
|
|
4
5
|
その id で findViewById(id) すれば該当の Button のインスタンスが得られます.
|
3
追記
answer
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[画面遷移の課題、numPickerとEditTextbuttonの対応について](https://teratail.com/questions/248448) で不足でしたら, そちらに追加してください.
|
|
2
2
|
|
|
3
|
-
レイアウトに配置した 36 個のボタンの id を配列に入れておき(仮に ```int[] buttons = new int[]{ R.id.button1, R.id.button2, ..., R.id.button36 };``` ), numPicker をそのインデックス ( buttons[numPicker-1] ) とすれば該当のボタンの id が得られます.
|
|
3
|
+
レイアウトに配置した 36 個のボタンの id を配列に入れておき(仮に ```int[] buttons = new int[]{ R.id.button1, R.id.button2, ..., R.id.button36 };``` ), numPicker をそのインデックス ( buttons[numPicker-1] ← numPicker は1始まり, 配列は0始まりなので-1している) とすれば該当のボタンの id が得られます.
|
|
4
4
|
その id で findViewById(id) すれば該当の Button のインスタンスが得られます.
|
|
5
5
|
文字を設定するなら ```(Button)findViewById(buttons[numPicker-1]).setText("あ");``` という感じになります.
|
|
6
6
|
|
2
追記
answer
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
[画面遷移の課題、numPickerとEditTextbuttonの対応について](https://teratail.com/questions/248448) で不足でしたら, そちらに追加してください.
|
|
2
2
|
|
|
3
|
-
レイアウトに配置した 36 個のボタンの id を配列(仮に int[] buttons = new int[]{ R.id.button1, R.id.button2, ..., R.id.button36 }; )
|
|
3
|
+
レイアウトに配置した 36 個のボタンの id を配列に入れておき(仮に ```int[] buttons = new int[]{ R.id.button1, R.id.button2, ..., R.id.button36 };``` ), numPicker をそのインデックス ( buttons[numPicker-1] ) とすれば該当のボタンの id が得られます.
|
|
4
4
|
その id で findViewById(id) すれば該当の Button のインスタンスが得られます.
|
|
5
|
+
文字を設定するなら ```(Button)findViewById(buttons[numPicker-1]).setText("あ");``` という感じになります.
|
|
5
6
|
|
|
6
7
|
先のご質問の回答では, 36 個ものボタンを1つ1つ xml に配置したり配列にするのが面倒でしたので, java コード内でボタンを生成しています.
|
1
追記
answer
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[画面遷移の課題、numPickerとEditTextbuttonの対応について](https://teratail.com/questions/248448) で不足でしたら, そちらに追加してください.
|
|
2
2
|
|
|
3
|
-
レイアウトに配置した 36 個のボタンの id を配列(仮に buttons[] )に入れておき, numPicker をそのインデックス ( buttons[numPicker-1] ) とすれば該当のボタンの id が得られます.
|
|
3
|
+
レイアウトに配置した 36 個のボタンの id を配列(仮に int[] buttons = new int[]{ R.id.button1, R.id.button2, ..., R.id.button36 }; )に入れておき, numPicker をそのインデックス ( buttons[numPicker-1] ) とすれば該当のボタンの id が得られます.
|
|
4
4
|
その id で findViewById(id) すれば該当の Button のインスタンスが得られます.
|
|
5
5
|
|
|
6
6
|
先のご質問の回答では, 36 個ものボタンを1つ1つ xml に配置したり配列にするのが面倒でしたので, java コード内でボタンを生成しています.
|