When the below method is called the dynamic layout will be filled to the parent_view.
public void Generate_tour_plan(String mark, OnClickListener o) {
parent_view = (LinearLayout) rootView
.findViewById(R.id.tour_iternary_wrapper);
hiddenInfo1 = getActivity().getLayoutInflater().inflate(
R.layout.tour_plan, null, false);
Button minus = (Button) hiddenInfo1.findViewById(R.id.plus);
minus.setText(mark);
CustomAutoCompleteTextView dealer_search = (CustomAutoCompleteTextView) hiddenInfo1
.findViewById(R.id.account_code);
CustomAutoCompleteTextView town_search = (CustomAutoCompleteTextView) hiddenInfo1
.findViewById(R.id.town);
town_search.setAdapter(city_adapter);
dealer_search.setAdapter(adapter);
minus.setOnClickListener(o);
parent_view.addView(hiddenInfo1, 0);
}
Here external layout will be added like a stack eg.(5,4,3,2,1)
, so I need to remove all the layout except first one.
for (int j2 = parent.getChildCount() - 1; j2 > 0; j2--) {
Log.i("TAG IS", j2 + "");
ViewGroup vv = (ViewGroup) parent.getChildAt(j2);
vv.removeAllViews();
}
Above code is for removing the items top to bottom.But this works on bottom to top. I want to remove the item like a stack.
You can use the ViewGroup.removeViews(start, count) method.
To remove all child views/layouts except the first one:
layout.removeViews(1, layout.getChildCount() - 1)
You can remove a Child View from a parent by calling removeView(View view)
, for example like this :
parent.removeView(child);
int count = (your viewGroup).getChildCount() - 1;
for (int i = count; i > 0; i--) {
(your viewGroup).removeViewAt(i);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With