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
1,212 PointsHelp 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
23,732 PointsCorrect 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:
<resources>
<!-- 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>
</resources>
Then in the layout file you can refer to it as:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Did you know?"
android:textSize="@dimen/text_size"
android:textColor="#80ffffff"/>

aakarshrestha
6,509 PointsI 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!
Arjun Vemperala
1,212 PointsArjun Vemperala
1,212 Pointsworked like a charm thankyou