简体   繁体   English

Android-如何将按钮文本更改为arraylist项目

[英]Android - How do I change button text to arraylist item

I've got a grid of nine buttons and at the moment each one displays the numbers 1-9 as text and another button which will change the numbered buttons text to a different number from 1-9 when clicked. 我有一个由9个按钮组成的网格,此刻每个按钮都将数字1-9显示为文本,另一个按钮将单击时将带编号的按钮文本更改为与1-9不同的数字。 So basically it will appear to shuffle the buttons around but really its just changing the text. 因此,基本上,它似乎会乱洗按钮,但实际上只是在更改文本。 Or is it easier to just shuffle the buttons? 还是只是随机播放按钮更容易?

Can I put the numbers 1-9 into a string array to get the button text to change to an item from the array? 我可以将数字1-9放入字符串数组中以获取按钮文本以从数组更改为项目吗? And how do I make sure it uses all the numbers 1-9 once? 以及如何确保它一次使用所有数字1-9?

I think changing the Button text will be more easier and faster than realigning the buttons itself will be more complicated. 我认为,与重新调整按钮本身相比,更改“按钮”文本将更加容易和快捷。 to change the button text value use this. 更改按钮文本值使用此。 I think you know this. 我想你知道这一点。

Button yourButton = (Button)findViewById(R.id.yourbt);
    yourButton .setText(stringarrayvalue);

So use a ArrayList of buttons and change the value of buttons from it .. 因此,使用按钮的ArrayList并从中更改按钮的值..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM