0

I'm trying to get views from another layout modified these and then add them to the current layout. This is what i'm doing.

myLayout looks as follows:

<LinearLayout>
  <RelativeLayout>
    <TextView>

And my code:

LinearLayout layout = (LinearLayout) findViewById(R.id.linear);
ViewGroup info = (ViewGroup) getLayoutInflater().inflate(R.layout.myLayout, layout,false); 
RelativeLayout relative = (RelativeLayout) info.getChildAt(1);
ViewGroup vg = (ViewGroup) hiddenInfo.getChildAt(1);
TextField tv = vg.getChildAt(1);
...modify tv...
layout.addView(relative);
layout.addView(tv);

Though my program always crashes as layout.addView, what am i doing wrong?

2
  • If your app crashes you should always post your logcat. Your RelativeLayout relative is already a child of info and a view can only have one parent so trying to use addView() will throw an exception. What are you really trying to do?
    – Sam
    Aug 30, 2012 at 0:48
  • what my topic says, i need to add a bunch of views dynamicly and want to prepare them in xml instead of setting it all in code, tried to do it all in code but that failed as well when adding. Is it that I can not add a relative layout that has elements in it to another view? Because i need to add unknown amounts of <RelativeView><TextView><TextView> to my current layout where i have to modify each textview individually
    – Alzorz
    Aug 30, 2012 at 6:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.