Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Time-consuming function call problem

Hi, I'm make an app that involves a 2-D array. and I have a functions refresh() that updates array based on the previous condition and a filltable() function, which fills the table using newly generated array. I'm planning on looping the process infinitely. However, it seems filltable() takes much long than refresh() to complete. When I tested the code with 2 iteration, 3 iteration,4 iternation... the code seems to ignore all filltable() but the last one, but still obtain the transformed array at the end(which means refresh() did work). So, how can I fix this Things I've tried-1 (using a loop):

for(int k=0; k<4; k++){
    fillTable(start,table); //start is the 2-D array
    start = refresh(start);
     }

Things I've tried-2 (using a delayed loop):

final Handler handler = new Handler();
    for(int k=0; k<4; k++){
    fillTable(start,table);
    handler.postDelayed(new Runnable() {
    @Override
    public void run() {
    start = refresh(start);//start is the 2-D array
    }
    }, 1000);
    }

Thanks ahead UPDATE1: somehow the format didn't work. Anyway, I have a 2-D array that contains string elements, and a function to refresh its elements based on previous state. Another function fillTable() will put corresponding image into a table layout, and this is also the function that kind lags. The dimension for the array goes up to 254 X 144 (pretty big). So, is there any way speed up such cell by cell update process using for() loops? and tricks or hints to improve the execution of such large array update?

2 Answers

This question may be better suited for a website like http://stackoverflow.com

Could you format the code please? :)

somehow the format didn't work. Anyway, I have a 2-D array that contains string elements, and a function to refresh its elements based on previous state. Another function fillTable() will put corresponding image into a table layout, and this is also the function that kind lags. The dimension for the array goes up to 254 X 144 (pretty big). So, is there any way speed up such cell by cell update process using for() loops? and tricks or hints to improve the execution of such large array update?