Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom views are slow
    text
    copied!<p>Im building a sudoku and Im facing a performance issue over here.</p> <p>I have this grid an I want to fill the grid with 81 cells. These cells are custom views, because I want them to have 10 labels in them en some function blabla.</p> <p>My problem now is that I have to create 81 subviews (no problem), fill them with data from my model (no problem) and then add the whole grid to my layout (biiiig problem).</p> <p>The whole building is done in a asynctask like this:</p> <pre><code>protected Void doInBackground(Void... params) { Model.Cell[][] sudoku = Controller.getInstance().startNewGame(); //call model for a new game ArrayList&lt;TableRow&gt; rows = ga.generateTable(sudoku); //generate the table tl = new TableLayout(ga); //create tablelayout //add the rows to the layout for (TableRow v : rows) { tl.addView(v); } return null; } </code></pre> <p>Then after this is done:</p> <pre><code>protected void onPostExecute(Void result) { super.onPostExecute(result); RelativeLayout rl = (RelativeLayout) ga.findViewById(R.id.gridContainer); //get the container //create layout rules android.widget.RelativeLayout.LayoutParams params = new android.widget.RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); params.addRule(RelativeLayout.CENTER_HORIZONTAL); //add the table to the container with the layout rl.addView(tl, params); //this is slow as hell. //stop loading indicator this.loading.dismiss(); } </code></pre> <p>I dont mind get a loading bar for a while. But my loading bar is stopping because rl.addView(tl, params) is superslow.</p> <p>Can somebody please help me how to keep my main thread fast?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload