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

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


Sponsored Links
 Hello,
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(
                                        R.layout.inner_layout, 
mContainerLayout);

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:

mContainerLayout.removeAllViews();

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:

mContainerLayout.removeAllViews();

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
instantiated?

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
removeAllViews().

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)
 http://commonsware.com 
_The Busy Coder's Guide to Android Development_ Version 2.0 Available!

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Other Threads

1. Retrieving Images

Hello Dear, I want to retrieve images from Android Media provider.
Here I want to limit the selection by TITLE, or LOCATION, or others. I
am trying in several ways. but getting problems.. you can see my....


Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;

        //displaySdCard();
//
//      String[] projection = {MediaStore.Images.ImageColumns._ID,
//                                                      
//MediaStore.Images.Media.TITLE,
//                                                      //"_display_name",
//                                                      
MediaStore.Images.Thumbnails.IMAGE_ID,
//                                                      
MediaStore.Images.Thumbnails.KIND,
//                                                      
MediaStore.Images.Media.DATA
//                                                      };
        String[] projection = {Media._ID,
                                                   Media.DISPLAY_NAME,
                                                   Media.TITLE,
                                                   
//MediaStore.Images.Thumbnails.IMAGE_ID
                                                        };


//      String[] projection = {Media._ID,
//                                                      
Images.Thumbnails.IMAGE_ID,
//
//                              };

        //String selection = MediaStore.MediaColumns.TITLE + "=ks";

        //String selection = MediaStore.Images.Thumbnails.KIND + " = " +
MediaStore.Images.Thumbnails.MINI_KIND;
        //String ks = "ks";
        //String selection = MediaStore.Images.Thumbnails.KIND + " = "
MediaStore.Images.Thumbnails.MINI_KIND + " AND " + Media.TITLE + " = "
+ ks ;
        //Log.i("me", selection);
        mCursor = this.managedQuery(uri, projection, null, null, null);



Any advice?

--~--~---------~--~----~------------~-------~--~----~

2. WebView word touching ability?

I was wondering whether there was a way, if you have a webview with
some html being displayed in it, to obtain which part of the html is
touched by the user.  For example, say I have a webview that's
displaying, in just plain text (no links), the following:

The quick brown
fox jumped over
the lazy dogs.

If the user touches the word "lazy", can I somehow obtain information
that he has touched that particular word?  Perhaps there is something
in the WebView or WebViewClient classes that maps sections in the html
data to x, y coordinates?

I'm not at all sure this is possible, but if anyone can point me in
the direction of any apps, code examples, or implementations that do
something like this, that would be awesome.  Thanks!

-Zack
--~--~---------~--~----~------------~-------~--~----~

3. AutoCompleteTextView and dropdown 2 lines

4. Use internal micorphone with headphones?

5. orientation change in xml.

6. Persistent data even when app uninstalled

7. Can I get user's gmail address or handset SN to verify them?