Problem with Android Programming. FOR

Asked

Viewed 19 times

1

I can’t generate the amount of EditTexts based on the parameter of for? Where is the error?

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main4);



    layout = (LinearLayout) findViewById(R.id.layoutEdits);

    int qtd = getIntent().getIntExtra("ValorDados", 0);
    vetorEdits = new EditText[qtd];

    for (int i = 0; i < qtd; i++) {

        vetorEdits[i] = new EditText(Main4Activity.this);
        vetorEdits[i].setHint("Valor do Edit " + (i+1));

        layout.addView(vetorEdits[i], new ViewGroup.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));

    }
  • Does an error appear ? If yes, which ? If not, what behavior does it show ?

  • Appears only 1 Edittext

  • Maybe because qtd = 1

  • @ramaral It was precisely what I was going to say. Confirm the value you have in qtd making Log of qtd before entering the for. If possible put up a print of this in the question

  • I got it. The problem was in XML. Thank you all.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.