Advertisement
Guest User

Untitled

a guest
Aug 1st, 2014
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. ArrayList<Character> answer = new ArrayList<Character>();
  2. ArrayList<Button> buttons = new ArrayList<Button>();
  3.  
  4. @Override
  5. protected void onCreate(Bundle savedInstanceState) {
  6. super.onCreate(savedInstanceState);
  7. setContentView(R.layout.activity_main);
  8.  
  9. Button btn1 = (Button) findViewById(R.id.button1);
  10. Button btn2 = (Button) findViewById(R.id.button2);
  11. Button btn3 = (Button) findViewById(R.id.button3);
  12. Button btn4 = (Button) findViewById(R.id.button4);
  13. Button btn5 = (Button) findViewById(R.id.button5);
  14. Button btn6 = (Button) findViewById(R.id.button6);
  15. Button btn7 = (Button) findViewById(R.id.button7);
  16. Button btn8 = (Button) findViewById(R.id.button8);
  17. Button btn9 = (Button) findViewById(R.id.button9);
  18. b.add(btn1);
  19. b.add(btn2);
  20. b.add(btn3);
  21. b.add(btn4);
  22. b.add(btn5);
  23. b.add(btn6);
  24. b.add(btn7);
  25. b.add(btn8);
  26. b.add(btn9);
  27.  
  28. String testAnswer = "Answer";
  29. //convert to chars and add to arraylist for shuffling
  30. for(char a : answer.toCharArray()){
  31. al.add(a);
  32. }
  33. Collections.shuffle(al);
  34.  
  35.  
  36. //loop over buttons and letters and assign each button with a letter
  37. for(char a : al){
  38. for(Button bb : b){
  39. bb.setText(String.valueOf(a));
  40. }
  41. }
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement