【发布时间】:2016-01-09 09:03:36
【问题描述】:
首先感谢您的帮助。 我正在创建一个计算器应用程序, 在 XML 文件中,我创建了按钮 [0-9] 现在我想把它们都放在按钮数组中
int NumberOfButtons=10;
Button button[] = new Button[NumberOfButtons];
这是数组, 在尝试使用数组之前,我创建了每个按钮
Button one, two, three, four, five, six, seven, eight, nine, zero, add, sub, mul, div, cancel,
equal;
现在这是通过 findValueid 连接的按钮
one = (Button) findViewById(R.id.button1);
two = (Button) findViewById(R.id.button2);
three = (Button) findViewById(R.id.button3);
four = (Button) findViewById(R.id.button4);
five = (Button) findViewById(R.id.button5);
six = (Button) findViewById(R.id.button6);
seven = (Button) findViewById(R.id.button7);
eight = (Button) findViewById(R.id.button8);
nine = (Button) findViewById(R.id.button9);
zero = (Button) findViewById(R.id.button0);
如何节省处理能力并使用更少的代码? 像 FOR 函数 或者也许使用 While
谢谢大家!
【问题讨论】:
标签: java android arrays button android-studio