A
A
Andrey Makarkin2018-05-04 15:29:55
Android
Andrey Makarkin, 2018-05-04 15:29:55

How to programmatically add ID to textview?

Good day everyone. Tell me, when we do markup, we write like this:

<TextView
                            android:id="@+id/comment_id"

Perfectly. And now we can access the TextView through its id.
How to programmatically add an id to this TextView?
We do this:
textView.setId(i);
where i is Int. In that case, everything works great. But if you try to add like this:
textView.setId(Integer.valueOf(string));
then the application crashes.
Why can we use the literal value of id in markup, but not programmatically?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
illuzor, 2018-05-04
@iLLuzor

Why can we use the literal value of id in markup, but not programmatically?

Because "literal value" is a variable, type int (R.id.your_id)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question