Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try as I might, I'm unable to come up with reasoning for why this is occurring (and I would happily upvote anyone who can explain it), but here is a solution. For some reason, Android isn't happy with you adjusting the XML inflated layout so close to its actual inflation in <code>setContentView()</code>. The solution is to do the dynamic portion of the layout process either in <code>onPostCreate()</code> or <code>onResume()</code>, depending on your Activity needs.</p> <p>I would recommend <code>onResume()</code> if you can afford it, since <code>onPostCreate()</code> is not typically suggested for override...however <code>onResume()</code> may be called to often and may mess up your layout. Here is your example modified to use <code>onPostCreate()</code> instead.</p> <pre><code>public class Main extends Activity { ArrayList&lt;AnswerView&gt; answers = new ArrayList&lt;AnswerView&gt;(); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TextView title = (TextView)findViewById(R.id.questionText); title.setText("This is a test"); } @Override protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); HashMap&lt;String, Drawable&gt; answerInfo = new HashMap&lt;String, Drawable&gt;(); Resources res = getResources(); answerInfo.put("a", res.getDrawable(R.drawable.flower_orange)); answerInfo.put("b", res.getDrawable(R.drawable.flower_white)); answerInfo.put("c", res.getDrawable(R.drawable.leaf)); answerInfo.put("d", res.getDrawable(R.drawable.flower_yellow)); setBoxes(answerInfo); } private void setBoxes(HashMap&lt;String, Drawable&gt; answerInfo) { LinearLayout answerList = (LinearLayout)findViewById(R.id.answerlist); AnswerView cb = null; //Remove all existing answer views answerList.removeAllViews(); answers.clear(); //For each possible answer create a answer views for (String s : answerInfo.keySet()) { cb = new AnswerView(this, s, answerInfo.get(s)); answers.add(cb); String text = cb.getText(); answerList.addView(cb); } } } </code></pre> <p>Two other things I noticed which may not affect you, but I figured I'd mention:</p> <ol> <li>If you want your items to always return in the same order, <code>HashMap.keySet()</code> is a bad choice. This method returns these values in different orders on different implementations. I would recommend a <code>LinkedHashMap</code> or a <code>List</code> if you need the order to always be the same.</li> <li>At least in this example, it doesn't make sense to clear your collections before setting them again...since this is only done when the Activity is reconstructed anyway. In the larger implementation, however, perhaps this has a larger purpose.</li> </ol> <p>Hope that Helps! Feel free to ignore anything that wasn't useful :)</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