Swapping in and out ViewGroups (Layout) within a container ViewGroup.

by steele johnson » Sat, 31 Jan 2009 05:56:58 GMT

Sponsored Links
I'm trying to dynamically swap in and out various layouts to one
layout container.

I've instantiated the container layout (mContainerLayout) by finding
it using the id through the maine Activity layout. This is successful.

Next, I add the inner layout by calling:

layoutInflater = this.getLayoutInflater();

and then inflating the inner layout like this:

mInnerLayout = (LinearLayout) layoutInflater .inflate(

This seems to work fine. I see the inner layout displayed in the
Activity that holds the containing layout. Next, I want to swap in
another inner layout, so I call:


and then I repeat the steps above. This is successful as well.

The problem is when I try to swap in and out the instantiated layouts
(the one that's returned from the inflate() call). When I call:


and then call:

mContainerLayout.addView(mInnerLayout );

I get a 'source not found' error.

My question is: how can I swap the Layouts that have already been

Thank you


Swapping in and out ViewGroups (Layout) within a container ViewGroup.

by Mark Murphy » Sat, 31 Jan 2009 06:02:15 GMT


Option #1: go the path you are trying

Option #2: use ViewFlipper or ViewSwitcher for parent container and have
it handle changing the children

Try removing the single view representing the "inner layout" instead of
the whole view tree. In other words, use removeView() instead of

Personally, I typically just use ViewFlipper, so it can handle this
case, plus give me the option for animating the transition between child
views if I so choose.

Mark Murphy (a Commons Guy)
_The Busy Coder's Guide to Android Development_ Version 2.0 Available!


Sponsored Links

Other Threads

1. Androi ASE

ASE will not install on my G1, I assume it is because I am running 1.5
and it requires 2.0.

I can get ASE to run on the Eclipse emulator when it is running 2.0
(not 1.5 or 1.6).

Is this correct and where is this described as a requirement for ASE?

(As an aside, the G1 downloads for 1.6 at HTC/developers are not
working - not sure what the problem there is...)


2. master clear programmatically


I find a permission named "android.permission.MASTER_CLEAR"  in uses-
permission list.But I didnt find any documentation regarding this.

Is it possible to master clear all the data in the phoneor set the
phone to factory settings....?

What I want to perform is to wipe the phone completely.For this I
tried to delete database tables.But it doesnt work.Here is my code:

getContentResolver().delete(People.CONTENT_URI, null, null);
        //       getContentResolver().delete(Uri.parse("content://calendar"),
null, null);
                 getContentResolver().delete(Browser.BOOKMARKS_URI, null, null);
                 getContentResolver().delete(Uri.parse("content://sms"), null,
(MediaStore.Images.Media.INTERNAL_CONTENT_URI, null, null);
(MediaStore.Video.Media.INTERNAL_CONTENT_URI, null, null);
(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, null, null);

I found unsupportedoperationException..........

is there any other way to do this????

I am in need of urgent help....
please help me!!!



3. Accessing built-in AAC decoder

4. How do I use getSharedPreferences on a non-visual class?

5. Contacts FAQ

6. Xl unlimited error

7. Where can I get android icons