how can i add more same layout more then one
View v = (LinearLayout) inflater.inflate(R.layout.tab_frag2_layout,container, false);
RelativeLayout tv = (RelativeLayout) inflater.inflate(R.layout.post_layout,container,false);
RelativeLayout tv2 = (RelativeLayout) inflater.inflate(R.layout.post_layout,container,false);
((LinearLayout) v).addView(tv);
((LinearLayout) v).addView(tv);
((LinearLayout) v).addView(tv);
((LinearLayout) v).addView(tv);
((LinearLayout) v).addView(tv);
if i do this it give me error and then if i do this it shows it only one time
View v = (LinearLayout) inflater.inflate(R.layout.tab_frag2_layout,container, false);
RelativeLayout tv = (RelativeLayout) inflater.inflate(R.layout.post_layout,container,false);
RelativeLayout tv2 = (RelativeLayout) inflater.inflate(R.layout.post_layout,container,false);
((LinearLayout) v).addView(tv);
((LinearLayout) v).addView(tv2);
what to do please help
First of all, there is no point in cast:
Remove cast, or change type of
vtoLinearLayout.It will be better if you’ll provide your log cat with error message, but I supose that you’re a getting
ClassCastExceptionhere:Maybe your
visn’tLinearLayout? If you’re not sure, try this one instead:EDIT
When you’re inflating layout the instance of
Viewis created. OneViewcan’t have more than 1 parent, so when you’re doing this:OS thinks that you’re trying to add another parent to
tv(it’s prohibited, so it’s throws an Exception)