How to set a text based on the Edittext id and not the Edittext name?

Asked

Viewed 1,487 times

1

when I set a text in an Edittext I do so.

EditText edit = new EditText(this);
edit.setId(0+4);
edit.setText("Meu Texto");

But I would like to set the text by id because in my case I have several editText called "Edit". They have the same name, but different ids. Is that possible? Thanks in advance.

  • 1

    I think I have an answer but, to be sure, I needed to check your code. I don’t see how you can have more than one variable called edit

  • i am dynamically creating editext’s, I created that Edittext within a "for", what differentiates editTexts are the ids, which I did that gambiarra to go incrementing and have different ids.

  • Those Edittext are associated with some View/Layout?

  • Yes, there is a Linearlayout, I am doing everything in the mother, without using anything in xml.

1 answer

3


If the Edittext are associated with a View/Layout can obtain the reference to each of them through the Id using:

EditText edit = (EditText)view.findViewById(id);  

view is the Linearlayout where the Edittext

  • Thanks ramaral, it was exactly what I needed!

Browser other questions tagged

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