I was wondering how to give a TextField an ‘id’ in java. So I am pretty much wanting to know how to give the TextField android:id=”@id/NAMEHERE” but do it in java. Here is the code so far:
TextView taskname = new TextView(this);
taskname.setText("Task " + tasknumber);
tasklayout.addView(taskname);
What do I need to add to give it an id?
If your question is to how to set id into activity, then understand purpose of id.
Id is specially required when you want to fetch view reference into activity class, where view has been declared into xml file. But in Activity, if you are creating any view, by
here, you already have view reference, but if you still want to set id, then you can use method