How to get the reference of a dynamically created Edittext when you click it?

Asked

Viewed 132 times

1

I 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 vector size is 3 and create 3 Textview and Edittexts on the screen. I create an id for each one, however when I run, on the screen it’s like there’s only 1 Edittext, in this case the last one, the 3rd one. it is as if the others did not exist,does anyone know how to solve this problem? I thank you already.

2 answers

0


  • I’m using Linearlayout and I’m using this click method and I still have the same problem.

0

The layout of the Views will depend on the type of parent Layout they were added to. As you see only 1 Edittext, please note that you are adding them to one Framelayout, that puts one element on top of the other... Linearlayout that when configured to have VERTICAL orientation, the child elements will be under each other, which should be what you are waiting for.

So check the type of 'layout' that you have.

  • I’m using the Linearlayout.

  • Use Linearlayout with VERTICAL Orientation.. See the constructor.

  • I was already using and finally solved the problem,I used a onFocusChangeListener to get the id of Edittext and inside I even called the textWatcher I needed to use, but vlw by the answers guy.

Browser other questions tagged

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