简体   繁体   中英

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. 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? And how do I make sure it uses all the numbers 1-9 once?

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 ..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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