Both work, obviously if you start concatenating you’ll need get string in order to avoid displaying an int.
Question: which is the most ‘elegant’ or ‘recommended’ to use?
Thank you
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The second approach is more elegant, since internally, the
TextView(or whateverView-class) will do the job of getting the String for your specified resource.Letting components do the internal work is always preferred. Also, it is shorter and more readable.
About the internals I talked about: If you have a look at Androids source-code, you can see that the
setText(int)-method ofTextViewis implemented like this:So, it internally uses the
Context-class to get the string from the resource-id. Now, if you look at thegetText()-method (which also comes from theContext-class), you can see that it is implemented the same way:So for performance or reliability reasons, it makes no difference. Still, it is shorter and more readable.