Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the content view dynamically

I am new to android and am trying to figure out how to change the contentView at will.

Right now, I have a TableLayout in the content view and it was set using the setContentView(TableLayout) method.

However, if I wanted to change this contentview within the same activity, how would I invoke this? Would I simply invoke the same method like: setContentView(TableLayout2) or would I need to clear the screen first?

What is the procedure for staying within the same activity and changing the content on the screen?

Thanks!

like image 677
locoboy Avatar asked Sep 06 '26 03:09

locoboy


1 Answers

This answer might help.

No, you can't call it multiple times easily. You either need to entirely remove all views and then inflate the new layout, or use a ViewFlipper (or FrameLayout) to switch between different views.

like image 103
Matthew Willis Avatar answered Sep 07 '26 18:09

Matthew Willis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!