Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


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,732 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!