Custom LinearLayout with inflate xml and child node
I have a custom navigation class where there are common views therefore i was thinking to put them into one layout which is to be inflated by the custom class and on the开发者_如何学编程 main layout ill put some navigation item on it.
Currently when i extends linearlayout, the views in the xml replaces all the views in the inflated view (i put this code on constructor)
((Activity) context).getLayoutInflater().inflate(R.layout.navigation_group, this ,true);
Is there a way where i could inflate a layout and get the child of the xml implementation and put it on one view? like
layout to be inflated
<com.mycompany.NavigationGroup> <Text android:text="title" ... /> <Button android:text="collapse" ... /> <LinearLayout android:id="@+id/navigationItemHolder ... /> <Text android:text="descriptions" ... /> </com.mycompany.NavigationGroup>
used in main layout
<com.mycompany.NavigationGroup> <Button android:text="menu 1" /> <Button android:text="menu 2" /> </com.mycompany.NavigationGroup>
My question is how could i put menu 1 & menu 2 inside navigationItemHolder? Thanks
You can do this programmatically after you inflate your layout. I believe you can do something like this:
YourLayout layout = (YourLayout)((Activity) context).getLayoutInflater().inflate(R.layout.navigation_group, this ,true);
layout.((LinearLayout)getChildAt (3)).addView (yourNavigationGroup);
精彩评论