0

My goal is to generate the layout of a view in Android Studios dynamically. The ultimate goal is to dynamically generate the following view

number - name - role

all on one line.

This is the current background code in Android Studio, which is currently setting the layout as follows

number
name
role

CODE

private void GenerateLayout()
{

    llisroles = findViewById(R.id.llRoles);

    for (int x = 0; x < num_players; x++)
    {

        TextView number = new TextView(this);
        EditText name = new EditText(this);
        Spinner role = new Spinner(this);
        //number.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
        //name.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));

        number.setText(names_players[x]);
        name.setText("");

        llisroles.addView (number);
        llisroles.addView(name);
        llisroles.addView(role);

    }



}
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
  • 1
    And your error/problem/question is? – PeS Oct 08 '18 at 00:42
  • To add views dinamically you nee to set the width and height of the views using a LayoutParams instance which in your case would be a LinearLayout.LayoutParams. The explanation is similar to this one https://stackoverflow.com/questions/52577994/with-framelayout-as-root-layout-add-view-on-top-of-another-one-with-offset-of/52578810#52578810 – Juan Oct 08 '18 at 00:53
  • What's with the loop anyway, do you want to create a list of horizontal linear layouts? – glagarto Oct 08 '18 at 03:57

0 Answers0