简体   繁体   中英

How can I define an ID for my EditText field programmatically?

I have an Activity in my App that adds more EditText fields to my view when a button is clicked.

Now I want to create a new ID for every created EditText-Field. Then I want to use

editText.setId(createdID);

And then I want to add this editText to an ArrayList (thats why I need the ID!)

editTextList.add((EditText) findViewById(createdID));

Any ideas? Thanks!

You can set it with TextView.setId(int id) . Try to see this question for more details. Android: View.setID(int id) programmatically - how to avoid ID conflicts?

Rather confusing idea. But if you really need - you can set tags to yours EditTexts

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM