Change Activity ContentView Dynamically

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Change Activity ContentView Dynamically

Postby rovi_android » Tue Sep 22, 2009 6:24 am

My application has many activities. When receiving a special event, I would like to inject a new view (not a dialog) as part of the window ( taking the top section of the Activity display area). My approach is to create a linearLayout, put he new view object and the existing Activity view inside then set the linearLayout as Activity's contentView.

The problem I am having is that I can't put the existing Activity View into LinearLayout, it complains already has a view parent. The existing Activity View is a type of Layout ( it can be LinearLayout, FrameLayout... depends on the Activities). Because my app has many activities and can use different types of layout, so the code need to treat them as a generic view object and insert into the new LinearLayout. The parent object for Activity layout object is an instance of ViewRoot and there is no method to remove the child View. Does anyone know what is the best solution for my problem?

Thanks,
Rovi
rovi_android
Freshman
Freshman
 
Posts: 2
Joined: Tue Sep 22, 2009 6:06 am

Top

Postby yaj786 » Tue Sep 22, 2009 8:03 pm

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2.  
  3.  
  4. <LinearLayout android:id="@+id/container"
  5.  
  6. android:layout_height="wrap_content"
  7.  
  8. android:layout_width="wrap_content" />
  9.  
  10.  
  11.  
  12. <LinearLayout android:id="@+id/addedViewContainer"
  13.  
  14. android:layout_height="wrap_content"
  15.  
  16. android:layout_width="wrap_content" />
  17.  
  18.  
  19.  
  20.  
  21.  
  22. </LinearLayout>
  23.  
  24.  
  25.  
  26. <LinearLayout android:id="@+id/restOfTheScreenContainer"
  27.  
  28. android:layout_height="wrap_content"
  29.  
  30. android:layout_width="wrap_content" />
  31.  
  32.  
  33.  
  34. /* REST OF YOUR ACTIVITY'S VIEWS */
  35.  
  36.  
  37.  
  38. </LinearLayout>
  39.  
  40.  
  41.  
  42. </LinearLayout>
  43.  
  44.  
  45.  
  46.  
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


Then in your java code:

LinearLayout addedViewContainer = (LinearLayout) findViewById(R.id.addedViewContainer);
addedViewContainer.addView(yourNewView);


I don't see any reason why this shouldn't work, but let me know.
yaj786
Developer
Developer
 
Posts: 33
Joined: Fri Jul 10, 2009 7:37 am

Postby rovi_android » Wed Sep 23, 2009 6:35 pm

yaj786,

Thanks for the reply. Your solution works if I have the handle of the layout object. However I need to support multiple activities and there can be any type of layout object (Linear, Frame...) So I need a generic solution which doesn't depend on the resource id. I think the solution should some how get the activity current layout object and put it into my new layout object along with my new view, but I havn't able to get it working.

Thanks,
Kevin
rovi_android
Freshman
Freshman
 
Posts: 2
Joined: Tue Sep 22, 2009 6:06 am

Postby yaj786 » Wed Sep 23, 2009 8:01 pm

Can you give us a real life example of what your application would be doing?

This seems like it might be a problem with the way your structuring your application.
yaj786
Developer
Developer
 
Posts: 33
Joined: Fri Jul 10, 2009 7:37 am

Postby sudheer1437 » Tue Oct 06, 2009 3:02 pm

Hi rovi_android

Hey i am too searching for a solution for the problem wad u r placing...

I have to add a view or a layout which is created dynamically, to present view....

i am unable to understand how to proceed,.....

Have u got any solution...?????
sudheer1437
Experienced Developer
Experienced Developer
 
Posts: 79
Joined: Sat Aug 08, 2009 7:42 am
Location: India

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 5 guests