Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Dynamically add buttons after spinner item selected
    primarykey
    data
    text
    <p>bit of a rough time getting this to work and its an understanding piece on my end...</p> <p>If i have a spinner item that contains the text "The [item] is [color]" and upon selecting this, I would like it to populate a... tablerow or something like that(or just a relativelayout)... with buttons and there would be two buttons, [item] and [color], stacked one on the other.</p> <pre><code>public void onItemSelected(AdapterView&lt;?&gt; parentview, View arg1, int position, long id) { final TableLayout t1 = (TableLayout)findViewById(R.id.button_items); final TableRow tr = new TableRow(t1.getContext()); ArrayList&lt;String&gt; words = Create_ArrayList(R.raw.titles); </code></pre> <p>// Create_ArrayList just parses known words like the [item] and [color] items and puts them into an array... for enumeration purposes later on.</p> <pre><code>String sentence = (String) spin.getSelectedItem(); if(sentence.contains("[item]")) { String line = words.get(1); ArrayList&lt;String&gt; x = getParts(line); </code></pre> <p>//arraylist should just be [item] and [color] at this point...</p> <pre><code> Toast.makeText(getBaseContext(), Integer.toString(x.size()), Toast.LENGTH_SHORT).show(); for(int i = 0; i&lt;x.size(); i++) { Toast.makeText(getBaseContext(), x.get(i), Toast.LENGTH_LONG).show(); Button btn = new Button(tr.getContext()); btn.setText(x.get(i)); btn.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); tr.addView(btn); t1.addView(tr, new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); } } } </code></pre> <p>but i keep getting...</p> <pre><code>java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first </code></pre> <p>and the buttons dont show up... app just crashes... into a mountain.</p> <p>help is much appreciated... Thanks all!</p>
    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.
    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