views:

542

answers:

1

Using Android, here is part of a layout xml file:

<LinearLayout
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:orientation="vertical"
   android:textColor="#191919">

      <TextView android:id="@+id/someTextField"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:layout_weight="1" 
       android:textStyle="bold" />

      <TextView android:id="@+id/anotherTextField"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:layout_weight="1" />

</LinearLayout>

I am adding this view (at runtime) to a ViewAnimator like this:

ViewAnimator viewAnimator = (ViewAnimator)findViewById(R.id.viewAnimator);
View newView = View.inflate(this, R.layout.new_view, null);
viewAnimator.addView(newView);
viewAnimator.showNext();

String newValue = "new value for the text field";
findViewById(R.id.deal_view).setVisibility(View.VISIBLE);
TextView someTextField = (TextView)findViewById(R.id.someTextField);
someTextField.setText(newValue);

This seems to be working fine, but when newValue is long enough to take more than 1 line of text in the layout, I am getting a crash:

09-06 21:36:48.208: ERROR/AndroidRuntime(6561): Uncaught handler: thread main exiting due to uncaught exception
09-06 21:36:48.248: ERROR/AndroidRuntime(6561): java.lang.StackOverflowError
09-06 21:36:48.248: ERROR/AndroidRuntime(6561):     at android.view.ViewGroup.drawChild(ViewGroup.java:1486)
09-06 21:36:48.248: ERROR/AndroidRuntime(6561):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
(many more lines like this)

Is this enough information to see what I might be doing wrong? It works perfectly fine when newValue is short enough for one line. I've thought about trying a TableLayout but it seems like this is exactly what a LinearLayout is good for.

A: 

Thanks for the help in the comments. I ended up taking the advice here (dropping ViewAnimator directly and using ViewFlipper). Better app, but still the same problem. I dropped one level of LinearLayout containers and it started working fine.

I'm assuming bhatt4982 is right, UI depth was too great.

bhatt4982, post your comment as an answer to get credit for this.

marcc