How do I get the reference of a dynamically created EditText when I click it?

1

I have created some TextViews and EditTexts dynamically as in the code below:

public void criaForm(){
    for (int i = 0; i < vet.length; i++) {

        TextView tv = new TextView(this);
        tv.setText(paises[i])
        layout.addView(tv);

        EditText et = new EditText(this);
        et.setId(i+x);
        layout.addView(et);
    }
      x = x+3;
}

In my case, the size of the vector is 3 and create 3 TextView and EditTexts on the screen. I create an id for each one, however when I execute, on the screen it is as if there is only 1 EditText, in the case the last one, the 3rd. It's as if others did not exist, does anyone know how to solve this problem? Thank you in advance.

    
asked by anonymous 20.08.2015 / 21:47

2 answers

0

A View reference that was clicked is passed by pro reference method that processes the event:

public void click(View view)

Now, this other problem is the fault of the layout, you should be using a FrameLayout, which stretches the Views daughters to occupy the entire space.

See more layouts: link

    
21.08.2015 / 08:01
0

The Views layout will depend on the type of parent Layout in which they were added. Since you only see 1 EditText, I assume you're adding them in a FrameLayout , which places one element on top of the other ... you could use for example the LinearLayout that when configured to have VERTICAL orientation, the child elements will be one underneath the other, which should be what you are expecting.

So check the type of ' layout ' you have.

    
21.08.2015 / 14:05