So if I’m dynamically creating textviews in a foreach loop and want to assign them IDs based on an incremental integer and then be able to retrieve the instance and text of the textview later using that ID, how would I do that. For example:
int my = 0;
foreach (equip item in list)
{
TableRow tr = new TableRow(this);
tv = new TextView(this);
tv.Text = "Test";
tv.Id = "Date" + my; //I want to make the ID the word Date + the current value of my
tr.AddView(tv);
tl.AddView(tr);
my++;
}
And then later get instance of that textview
TextView tv = (TextView)"Date" + my;
Doing the above results in “Cannot convert type string to int’ on the line where I assign tv the ID and “Operator + cannot be applied to operands of type Android.Widget.Textview and int”.
That’s not really the intended use of view IDs, which should be positive integers. In this case you would have to set the ID simply to the number, instead of prepending it with “Date”.
Another option is to use tags. You could do something like this:
You can then look up views by their tag, assuming you have a reference to a view containing the view you’re looking for (your TableLayout in this case would work):