Let’s get straight to code.
Activity Code, onCreate method
setContentView(R.layout.main);
View main_view = findViewById(R.id.main_view);
View view_flipper = main_view.findViewById(R.id.vf);
View first_tab = view_flipper.findViewById(R.id.prev_pane);
The main.xml layout code:
<ViewFlipper android:id="@+id/vf"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<include android:id="@+id/prev_pane" layout="@layout/vf_inner" />
<include android:id="@+id/cur_pane" layout="@layout/vf_inner" />
<include android:id="@+id/next_pane" layout="@layout/vf_inner" />
</ViewFlipper>
The problem!
Main view is correctly found, so is ViewFlipper, yet prev_pane or cur_pane or next_pane are not found, a null pointer is returned. Any ideas why?
This activity is called through a tab by using an Intent. All references are resolved correctly except id’s on includes
When I inspect variables, I find the contents of vf_inner layout in mChildren
That’s because
<include />tags are not an actual view in your UI hierachy.They are more of a copy&paste instruction for the android tools.
If you want to find the panes at runtime, add the IDs to the root elements of the included layouts. This way they can be found via
findViewById().