Chapter 6

Working with Java Types

IN THIS CHAPTER

check Getting input from the user

check Displaying all kinds of values

check Converting from one type of value to another

“You can't fit a square peg into a round hole,” or so the saying goes. In Java programming, the saying goes one step further: “Like all other developers, you sometimes make a mistake and try to fit a square peg into a round hole. Java's type system alerts you to the mistake and prevents you from running the flawed code.”

Working with Strings

Chapter 5 introduces int values, double values, String values, and other kinds of values. Android doesn't let you mix these values willy-nilly. You can't plop an int value into a TextView component and expect things to go smoothly. TextView components want their contents to be String values.

But values don't live in vacuums. Sometimes you want to display a number such as an int value on the user's screen. So what can you do?

You can check some of the ideas in this section. That's what you can do.

Going from primitive types to strings

Chapter 5 gives you one way to get a String value from a numeric value: Put a plus sign between the numeric value and some other String value. For example, ...

Get Java Programming for Android Developers For Dummies, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.