Johann
Johann

Reputation: 29877

Is findViewById still needed

Recently after getting back into Android development, as I was reviewing some code, I noticed that code would reference a control directly by its id without the need to use findViewById. So if I had a textview with an id of tvUsername, I could just call:

tvUsername.setText("john");

In the past I was always using findViewById but am now wondering whether the ability to use a control directly without calling findViewById always existed, or did Google start supporting directly referencing it after some version.

Upvotes: 4

Views: 579

Answers (1)

AskNilesh
AskNilesh

Reputation: 69709

Is findViewById still needed

Is findViewById still needed if you are using JAVA than it is needed,

But if you use Data Binding Library then no need to do findViewById

Also in KOTLIN the findViewById is not needed

You can directly use it like this

tvUsername.text ="john"

for more information read

Upvotes: 4

Related Questions