为了账号安全,请及时绑定邮箱和手机立即绑定

通过循环数组设置button的id

通过循环数组设置button的id

ibeautiful 2019-03-14 14:15:42
通过循环设置5个button的id,每次都随机分配。随机分配没有问题。在使用两个方法,随机设置button的id以及设置文本的时候出现错误。弄得很混乱不知道问题出在哪里了?Button b1, b2, b3, b4, b5; Button[] buttons = { b1, b2, b3, b4, b5 }; public void shuffleButtons() {         Integer[] Id = { R.id.bChoice1, R.id.bChoice2, R.id.bChoice3,                 R.id.bChoice4, R.id.bChoice5 };         ArrayList<Integer> buttonId = new ArrayList<Integer>(Arrays.asList(Id));         Collections.shuffle(buttonId);             for (int x = 0; x < 5; x++) {                 for (Button b : buttons) {                     b = (Button) findViewById(buttonId.get(x));                 }             }     }public void setButtonTxt() {             for (Button b : buttons) {                 for (int x = 0; x <= buttons.length; x++) {                     b.setText(textList.get(x));                 }             }     }
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 337 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号