Retrieving texts typed in Edittext generated at runtime

Asked

Viewed 210 times

1

In my project I have some Edittext being generated at runtime, the number of Edittext is variable.
I need to retrieve the typed text and store it in different variables, then create a Json object with it.

Here is the method I use to create the Edittext:

public View editText(String nmLabel, String tpRender) {
    EditText e = new EditText(getBaseContext());
    e.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    // e.setHint("DATE");

    if(tpRender.equals("NUMBER")) {
        e.setHint("NUMBER");
    }
    else if(tpRender.equals("DATE")) {
        e.setHint("DATE");
    }
    else if(tpRender.equals("TEXT")) {
        e.setHint("TEXT");
    }
    e.setTextColor(Color.BLACK);
    e.setTextSize(20);

    return(e);
}

How do I get the texts typed separately?

1 answer

0


Assign a different id to each of them using e.setId(int id)

You can then access them using the method findViewById() view(layout) where they were inserted.

  • It worked 100%, thank you!

Browser other questions tagged

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