整数 0,1,2,3,4 のリストがあります。次に、シャッフルします。3 番目のステップとして、button1 に関連する最初のオブジェクト、button2 に関連する 2 番目のオブジェクトなどでボタンを初期化します。手動で行うと機能しますが、動的に解決したいと考えています。
List<Integer> objects = new ArrayList<Integer>();
objects.add(0);
objects.add(1);
objects.add(2);
objects.add(3);
objects.add(4);
// Shuffle the collection
Collections.shuffle(objects);
//this is not working here, but it should reflect what i am trying to achieve here
// -->
for (int i = 0; i<objects.size(); i++) {
Button button**i** = (Button)findViewById(R.id.button**i**);
button**i**.setText(objects.get(i).toString());
}
前もって感謝します。助けていただければ幸いです(正しい方向に鼻を突っ込んでください)