Mark,
Thanks for your prompt reply.
False alarm.
When we use include in xml file, to reuse a ui element we specify a
unique id for each include. Obviously, in code I need to create a new
ViewGroup everytime I reuse the ui :). I was expecting to just work by
addView without having to create a new instance. Silly me.
Old code
rootView = rootActivity.getLayoutInflater().inflate(R.layout.rootview,
null);
LinearLayout parentView = (LinearLayout)
rootView.findViewById(R.id.rootView) ;
View childView = rootView.findViewById(R.id.childView) ;
for (int rowCount = 0 ; rowCount < 5 ; rowCount ++) {
rootView.add(childView);
}
new code
rootView = rootActivity.getLayoutInflater().inflate(R.layout.rootview,
null);
LinearLayout parentView = (LinearLayout)
rootView.findViewById(R.id.rootView) ;
for (int rowCount = 0 ; rowCount < 5 ; rowCount ++) {
LinearLayout holder = new
LinearLayout(mainActivity) ;
holder.setId (rowCount)
View childView =
rootView.findViewById(R.id.childView) ;
holder.addView(childView) ;
rootView.add(childView);
}
This worked.
Conny
On Jul 12, 12:49 am, Conny <[email protected]> wrote:
> Correction.
>
> I am able to add one view to the placeholder, but unable to add more
> than one. I get this exception
>
> 07-12 01:15:05.508: ERROR/AndroidRuntime(426):
> java.lang.IllegalStateException: The specified child already has a
> parent. You must call removeView() on the child's parent first.
> 07-12 01:15:05.508: ERROR/AndroidRuntime(426): at
> android.view.ViewGroup.addViewInner(ViewGroup.java:1970)
> 07-12 01:15:05.508: ERROR/AndroidRuntime(426): at
> android.view.ViewGroup.addView(ViewGroup.java:1865)
> 07-12 01:15:05.508: ERROR/AndroidRuntime(426): at
> android.view.ViewGroup.addView(ViewGroup.java:1845)
> 07-12 01:15:05.508: ERROR/AndroidRuntime(426): at
> SOMEPACAGE.createView(MYJAVACODE.java:111)
> 07-12 01:15:05.508: ERROR/AndroidRuntime(426): at
> SOMEPACAGE..run(MYTHREADINPARALLE.java:25)
> 07-12 01:15:05.508: ERROR/AndroidRuntime(426): at
> java.lang.Thread.run(Thread.java:1096)
> 07-12 01:15:05.568: WARN/ActivityManager(58): Force finishing
> activity SOMEPACAGE.
> 07-12 01:15:06.418: ERROR/WindowManager(426): Activity SOMEPACAGE.has
> leaked window com.android.internal.policy.impl. that was originally
> added here
> 07-12 01:15:06.418: ERROR/WindowManager(426):
> android.view.WindowLeaked: Activity SOMEPACAGE. has leaked window
> that was originally added here
> 07-12 01:15:06.418: ERROR/WindowManager(426): at
> android.view.ViewRoot.<init>(ViewRoot.java:247)
> 07-12 01:15:06.418: ERROR/WindowManager(426): at
> android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
> 07-12 01:15:06.418: ERROR/WindowManager(426): at
> android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
> 07-12 01:15:06.418: ERROR/WindowManager(426): at
> android.view.Window$LocalWindowManager.addView(Window.java:424)
> 07-12 01:15:06.418: ERROR/WindowManager(426): at
> android.app.Dialog.show(Dialog.java:241)
> 07-12 01:15:06.418: ERROR/WindowManager(426): at
> 07-12 01:15:06.418: ERROR/WindowManager(426): at
> android.view.View.performClick(View.java:2408)
> 07-12 01:15:06.418: ERROR/WindowManager(426): at android.view.View
> $PerformClick.run(View.java:8816)
> 07-12 01:15:06.418: ERROR/WindowManager(426): at
> android.os.Handler.dispatchMessage(Handler.java:92)
> 07-12 01:15:06.418: ERROR/WindowManager(426): at
> android.os.Looper.loop(Looper.java:123)
> 07-12 01:15:06.418: ERROR/WindowManager(426): at
> android.app.ActivityThread.main(ActivityThread.java:4627)
> 07-12 01:15:06.418: ERROR/WindowManager(426): at
> java.lang.reflect.Method.invokeNative(Native Method)
> 07-12 01:15:06.418: ERROR/WindowManager(426): at
> java.lang.reflect.Method.invoke(Method.java:521)
> 07-12 01:15:06.418: ERROR/WindowManager(426): at
> com.android.internal.os.ZygoteInit
> $MethodAndArgsCaller.run(ZygoteInit.java:868)
> 07-12 01:15:06.418: ERROR/WindowManager(426): at
> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
> 07-12 01:15:06.418: ERROR/WindowManager(426): at
> dalvik.system.NativeStart.main(Native Method)
>
> Conny
>
> On Jul 12, 12:37 am, MCON Dev <[email protected]> wrote:
>
>
>
> > So I read the xml tricks 2 from developer.android.com, and it worked for me.
> > But I need to programmatically include 1 xml into another. addview returns
>
> > 07-12 01:01:18.429: ERROR/AndroidRuntime(267):
> > java.lang.IllegalStateException: The specified child already has a parent.
> > You must call removeView() on the child's parent first.
> > 07-12 01:01:18.429: ERROR/AndroidRuntime(267): at
> > android.view.ViewGroup.addViewInner(ViewGroup.java:1970)
>
> > ((ViewGroup) placeHolderProductList).addView(productList,
> > new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
> > LinearLayout.LayoutParams.WRAP_CONTENT)) ;
>
> > Please help.
> > Conny
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en