0

Possible Duplicate:
switching xml layout causes crash in Android

I have many xml layouts with image backgrounds and Buttons. I need to switch layouts so I use this function many times setContentView(R.layout...);

it causes crash at 4. or 5. call of setContentView() because of previous layouts... using of System.gc(); Runtime.getRuntime().gc();

didn't work.

Community
  • 1
  • 1
betula
  • 1

1 Answers1

0

I think instead of setting content view for activity every time, you can add and remove views(other xml layouts) to and from main layout based on requirement. For example

main_layout.addView(view);

before adding other view, you have to remove view like below

main_layout.removeAllViewsInLayout();

Hope it helps.

Braj
  • 2,164
  • 2
  • 26
  • 44