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 trialArjun 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,733 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