How to add a group of View-elements from an HTML file using the method? This group can be, for example, a container Linear Layout with a text header, buttons, a picture, and anything else.

Why it is needed: if it were necessary to add, for example, just one button, then the code would be very small, but if you need to insert a composite object (container + content with a configured mutual location), then it is certainly rational to take the added object into an XML file .

In order not to spend a lot of time on the answer, you do not need to write a complete example with a working java and xml file, just insert the minimum required number of lines into this method:

public void AddViewGroup(View viewGroup){ // Добавляем содержимое, допустим, из groups.xml } 
  • one
    In Java, method names are written with a small letter, and class names are written with a large one. It may seem like nonsense to you and you are so special that the convention of the language is on your drum, but other programmers will think all sorts of nasty things about you until you begin to observe this convention. - pavlofff
  • No, it doesn’t seem nonsense to me, just gathering information that you can write with which letter indefinitely and never start programming. But now, when you made a comment, I will write code in accordance with these rules. - Lateral Gleb
  • In fact, there are very few naming rules . The full convention , of course, is somewhat more voluminous, but it is not necessary to collect this information - it is already collected in one place and divided into chapters and paragraphs for better perception. - pavlofff
  • Google has additionally its code design guidelines for Android developers - pavlofff

1 answer 1

 public void AddViewGroup(View viewGroup){ View group = getLayoutInflater().inflate(R.layout.groups, null); viewGroup.addView(group); } 
  • Nevertheless, it is not worthwhile to encourage the "free" style of comrades who do not respect the agreements and write methods with a capital letter. If a person does not want to follow the convention, then he must adapt to the correct spelling, and not you under it - pavlofff
  • @pavlofff, I agree, just copy the name of the method from the question. - Nikotin N