How to create an Android user control and use it in Xml?

I understand how to create an Android user control, and I believe that I understand how to extract attributes for it from the Xml layout. However, I do not know how to get any children from it.

Here is a visual example of what I'm trying to accomplish:

public class Menu extends LinearLayout
{
    // Custom Code
}

public class MenuItem extends Button
{
    // Custom Code
}

<!-- Layout -->
<?xml version="1.0" encoding="utf-8"?>
<Menu>
    <MenuItem/>
    <MenuItem/>
</Menu>

When my Menu is created, how do I get links to two MenuItems?

+3
source share
2 answers

For this you must use android:id. If you do not know how many children you have:

LinearLayout extends ViewGroup, getChildAt() getChildCount(), .

+1

( ) . , . , .

0

Source: https://habr.com/ru/post/1758658/


All Articles