Element IDs are pure integers, they can't be set as strings. IDs assigned to elements created in XML are converted into an integer internally and stored as an int.
Dynamically created elements always have a ID of -1 by default. They can be manually assigned an ID through setID() but there is a chance of collision with other IDs created automatically by the system.
To prevent such a collision, the method given in this answer may be used to manually assign an ID.
EDIT: Basically, the link says that if you have API level 17+, you use View.generateViewId()
else if you do it manually, you don't go above 0x00FFFFFF as an ID as these are reserved for statically created elements. Other than that, avoid conflicts among IDs created through your code.
However, in the case of this question, a LinearLayout may be a better way to go.
Suppose this is your XML.
<LinearLayout
android:id="@+id/list"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical"
android:gravity="center_horizontal"/>
The Java code to add an EditText to this may be something like the following:
List<EditText> edittexts;
...
LinearLayout rel=(LinearLayout) getView().findViewById(R.id.list);
...
void addEditText(Context myContext,int edittextno)
{
EditText ed=new EditText(myContext);
ed.setText("EditText"+edittextno);
LayoutParams lParamsMW = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
ed.setLayoutParams(lParamsMW);
edittexts.add(ed);
rel.addView(ed);
}
You can modify all the created EditTexts through the List edittexts.
The vertical LinearLayout automatically gives the vertical list format required by the OP. A margin can be added to each added element if required. If required to add more elements to the left or right of the EditText, a horizontal LinearLayout may be dynamically created, elements added to it and the horiz. LinearLayout added to the static one in a similar manner as in the code above.