Assign to dynamically created editText

With thanks to stackoverflow, 2 methods, 1 simple and one less simple.

1) You can assign an id after creating the edit text and before adding it to the layout.


This doesn’t put it in the file (so you can’t use findViewById( but you can use


where int is the same number used to set the id.


Create a new xml file named ids.xml inside res/values folder.

Add new item like:

<?xml version="1.0" encoding="utf-8"?>
    <item type="id" name="button_group_cancel" />

Now you can set the id to edit text as:



This entry was posted in Android. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *