Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I dynamically add Views that use XML Layouts to the ContentView?
    primarykey
    data
    text
    <p>Within my main Activity, I create a FrameLayout with child Views and set it as the ContentView. Now, staying within the same Activity, after onCreate() has executed fully, I need to be able to add and remove child Views from the FrameLayout, dynamically. I achieved this by using a Handler to pause the main Thread and then add or removed the child Views as needed.</p> <p>This all works great when I am dealing with Views that I programmatically create, but when I attempt to do the same with a View that uses a XML layout, I get a Null Pointer Exception from the ViewGroup that I am trying to add to the FrameLayout.</p> <p>Are there specific steps I can use to achieve this without the use of Fragments?</p> <p>I can elaborate more if some don't understand what I am asking. I could provide code chunks if it would help but I think most will get the gist of what I am doing from my short explanation. I am just looking for someone to point me into the right direction.</p> <p>Here is the LogCat chunk for the exception taht was thrown:</p> <pre><code>11-15 13:40:42.977: E/AndroidRuntime(14956): FATAL EXCEPTION: main 11-15 13:40:42.977: E/AndroidRuntime(14956): java.lang.NullPointerException 11-15 13:40:42.977: E/AndroidRuntime(14956): at android.view.ViewGroup.addView(ViewGroup.java:1821) 11-15 13:40:42.977: E/AndroidRuntime(14956): at android.view.ViewGroup.addView(ViewGroup.java:1808) 11-15 13:40:42.977: E/AndroidRuntime(14956): at com.beastcodes.framework.impl.AndroidGame.addScreenFragment(AndroidGame.java:207) 11-15 13:40:42.977: E/AndroidRuntime(14956): at com.beastcodes.framework.impl.AndroidGame.addAllScreenFragments(AndroidGame.java:213) 11-15 13:40:42.977: E/AndroidRuntime(14956): at com.beastcodes.framework.impl.AndroidGame.access$2(AndroidGame.java:211) 11-15 13:40:42.977: E/AndroidRuntime(14956): at com.beastcodes.framework.impl.AndroidGame$3.run(AndroidGame.java:61) 11-15 13:40:42.977: E/AndroidRuntime(14956): at android.os.Handler.handleCallback(Handler.java:587) 11-15 13:40:42.977: E/AndroidRuntime(14956): at android.os.Handler.dispatchMessage(Handler.java:92) 11-15 13:40:42.977: E/AndroidRuntime(14956): at android.os.Looper.loop(Looper.java:130) 11-15 13:40:42.977: E/AndroidRuntime(14956): at android.app.ActivityThread.main(ActivityThread.java:3691) 11-15 13:40:42.977: E/AndroidRuntime(14956): at java.lang.reflect.Method.invokeNative(Native Method) 11-15 13:40:42.977: E/AndroidRuntime(14956): at java.lang.reflect.Method.invoke(Method.java:507) 11-15 13:40:42.977: E/AndroidRuntime(14956): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907) 11-15 13:40:42.977: E/AndroidRuntime(14956): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665) 11-15 13:40:42.977: E/AndroidRuntime(14956): at dalvik.system.NativeStart.main(Native Method) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload