Tuesday, May 30, 2017

TextView.setText() - be careful with overloaded variations of this method

In Android native development, when using TextView's setText() function, one needs to be careful to use a proper overloaded version.

For example, if you provide a string as the first and only parameter of this function, it will set the label of the component to that string. This is usually what developer wants.

However, if you provde an integer as parameter, then setText() will search for a resource with corresponding Resource ID. It won't simply convert to string and display that value. If the resource is not found, it will throw the following error:

Android Resources$NotFoundException: Resource ID .... not found


Therefore, double check this function:)

No comments:

Post a Comment

Ubuntu 12.04, 14.04, 16.04 - auto start an app or script before login

To run a command or application at startup, even before the user has logged in, you can use this file: /etc/rc.local The commands entered...