Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ArrayList<Character> answer = new ArrayList<Character>();
- ArrayList<Button> buttons = new ArrayList<Button>();
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- Button btn1 = (Button) findViewById(R.id.button1);
- Button btn2 = (Button) findViewById(R.id.button2);
- Button btn3 = (Button) findViewById(R.id.button3);
- Button btn4 = (Button) findViewById(R.id.button4);
- Button btn5 = (Button) findViewById(R.id.button5);
- Button btn6 = (Button) findViewById(R.id.button6);
- Button btn7 = (Button) findViewById(R.id.button7);
- Button btn8 = (Button) findViewById(R.id.button8);
- Button btn9 = (Button) findViewById(R.id.button9);
- b.add(btn1);
- b.add(btn2);
- b.add(btn3);
- b.add(btn4);
- b.add(btn5);
- b.add(btn6);
- b.add(btn7);
- b.add(btn8);
- b.add(btn9);
- String testAnswer = "Answer";
- //convert to chars and add to arraylist for shuffling
- for(char a : answer.toCharArray()){
- al.add(a);
- }
- Collections.shuffle(al);
- //loop over buttons and letters and assign each button with a letter
- for(char a : al){
- for(Button bb : b){
- bb.setText(String.valueOf(a));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement