Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Arjun Vemperala
Arjun Vemperala
1,212 Points

Help in creating string for numbers

i don't want to hard code numbers (which is in the video Adding a text view) i know how to add strings for words and use it as reference but don't know about numbers please help

2 Answers

Kourosh Raeen
Kourosh Raeen
23,733 Points

Correct me if I'm wrong, but I assume you are referring to Build a Simple Android App course and the textSize value of 24sp. You could create integer resource files just like string ones but in this case it wouldn't work since it is 24sp and not just integer 24. What you could do is to add another entry in the dimens.xml file as follows:

    <!-- Default screen margins, per the Android Design guidelines. -->
    <dimen name="activity_horizontal_margin">50dp</dimen>
    <dimen name="activity_vertical_margin">50dp</dimen>
    <!-- Default text size. -->
    <dimen name="text_size">24sp</dimen>

Then in the layout file you can refer to it as:

        android:text="Did you know?"
Arjun Vemperala
Arjun Vemperala
1,212 Points

worked like a charm thankyou

6,509 Points

I am not exactly sure what you want to solve... but if you want to store numbers in a variable then you can do this: E.g: If you want to store a number value 5 in a variable then you can do it so by: int numberValue = 5;

Here int is a datatype, numberValue is the name of the variable that holds the value 5. Now you can use numberValue to pass the value 5.

Hope it helps!

Happy Coding!