• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Android: Randomly swap buttons positions to predefined positions

Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I'm having trouble working out how to implement an idea I have had. I have 9 buttons number 1,2,3... and so on. The 9 buttons are layed out as if it is a three by three grid. I need to keep this layout but I want to swap the images around the predefined locations for example the layout of the buttons might be like so:

1 2 3
4 5 6
7 8 9

but upon button press the layout would randomly swap keeping the square shape and may look like this:
9 1 5
7 8 3
2 6 4

each button press would randomly swap the buttons around keeping the above structure.

I understand how to set button position programmatically but yet to figure out away to achieve what I want or at least efficiently. This is my class so far for setting the button location which all it does is set images in totally random places:

A different idea i have sets the images location corretly but keeps it static as I haven't figured out how to combine the random without breaking my design plan.:

Guidance on this would be great, hopefully I have explained my goal clear enough. I can find loads on randomly moving images and button but not cycling them through predefined coords
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic