Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Dynamically add views to ScrollView
    primarykey
    data
    text
    <p>I have a ScrollView and I want to insert a user specified number of HorizontalScrollViews. So what user says he wants to have a matrix of 5x5 elements, I want to insert 5 HorizontalScrollViews with 5 EditText objects each. My program adds the first line just as it's supposed to, but the rest not.</p> <pre><code>for (int i = 0; i &lt; number; i++) { LinearLayout ll = new LinearLayout(this); ll.setLayoutParams(par2); HorizontalScrollView row = new HorizontalScrollView(this); row.setLayoutParams(par1); row.addView(ll); for (int j = 0; j &lt; number; j++) { EditText txt = new EditText(this); txt.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); txt.setHint(i+","+j); ll.addView(txt); } latout_in_scrollview.addView(row); } </code></pre> <p>Any ideas why? Thanks!</p> <p>EDIT: The 1:1 code im using</p> <pre><code>LinearLayout dijkstra_rows; FrameLayout.LayoutParams par1 = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams par2 = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout_dijkstra); dijkstra_rows = (LinearLayout) findViewById(R.id.dijkstra_rows); Bundle extras = getIntent().getExtras(); number = extras.getInt("vertexes"); for (int i = 0; i &lt; number; i++) { LinearLayout ll = new LinearLayout(this); ll.setLayoutParams(par2); HorizontalScrollView row = new HorizontalScrollView(this); row.setLayoutParams(par1); row.addView(ll); for (int j = 0; j &lt; number; j++) { EditText txt = new EditText(this); txt.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); txt.setHint(i+","+j); ll.addView(txt); } dijkstra_rows.addView(row); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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