Results 1 to 2 of 2
  1. #1
    Ikarus Fox is offline Member
    Join Date
    Aug 2013
    Rep Power

    Default 2D Array on a Android screen?

    Hey guys,

    i'm working on a game and got a problem: how do i make a chess like field with a 2d array and then bring it on the screen, using XML on android?

    lets say i do this:
    public static void main (String [] args) {

    int [][] galaxy;
    galaxy = new int [8][10];
    then i would have a "galaxy" that is 8x10 fields

    now i use some random nummbers to make some of those fields into solar systems, then i want to give the solar systems a JPG and make it so that i can klick on them, so i can open a screen to select the planets in the system.

    can anyone give me a hint? google didnt help so far and i'm starting to get frustrated about it, because i cant find anything that brings life into my black void

    best regards,

  2. #2
    Kris3579 is offline Member
    Join Date
    Dec 2013
    Rep Power

    Talking Re: 2D Array on a Android screen?

    It seems that you are trying to accomplish a 2d grid. You could do this instead by
    declaring and initializing a Point as a grid size. Which is what I did for an app I am working on.

    Java Code:
    public class MyClass extends View {
        Point gridSize;
        public MyClass(Context context) {
            gridSize = new Point(32, 32);
        protected void onDraw(Canvas canvas) {
            Paint pen = new Paint();
            for (int x = 1; x < (int) Math.round(this.getWidth()/gridSize.x); x++) {
                canvas.drawLine((float) x*gridSize.x, (float) 0, 
                (float) x*gridSize.x, (float) this.getHeight(), pen);
            for (int y = 1; y < (int) Math.round(this.getHeight()/gridSize.y); y++) {
                canvas.drawLine((float) 0, (float) y*gridSize.y, 
                (float) this.getWidth(), (float) y*gridSize.y, pen);
    Last edited by Kris3579; 12-23-2013 at 10:12 AM.

Similar Threads

  1. formatting output from array to screen
    By BriMan83 in forum New To Java
    Replies: 3
    Last Post: 01-24-2013, 05:46 PM
  2. Storing a 2D Array in Android
    By driiper in forum Android
    Replies: 3
    Last Post: 09-17-2012, 02:04 PM
  3. Replies: 9
    Last Post: 09-06-2012, 09:37 AM
  4. JSON Array Loop Inserting into Android SQLite Database
    By viviosoft in forum New To Java
    Replies: 6
    Last Post: 09-26-2011, 10:34 AM
  5. choosing random array to print to screen
    By debugdoug in forum New To Java
    Replies: 4
    Last Post: 04-05-2011, 03:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts