• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Random noob question

dothackjhe

Newbie
Given the syntax setContentView (R.layout.main), we're calling on values stored from within the R.java right? But how do we call on "externalized" resources stored, for example, in the res/values/strings.xml, res/drawable, etc.?

I've been having trouble with this lately as this is the first time I actually delved into this language. What's worst is that Eclipse Juno IDE + Android Plugin randomly deletes the R.java from within the package which complicates things all the more.

Given these details:
Project Name: TriviaQuiz
Build Target: Android Google APIs 2.2
App Name: Been There, Done That!
Package Name: ph.edu.comteq.triviaquiz
Create Activity: QuizSplashActivity

Must the setContentView() really contain R.layout.main? I think I'm having trouble on this part as my external resources within the package are just fine.
 
The getResources() function might interest you. Following functions from there have lead to my own projects using the content from the res folder.

Also, the setContent() function can also use SurfaceView and GLSurfaceView extending objects
 
What should be contained within the setContentView() then if my resources are externalized and are outside of R.java? I'm getting this as R.java having its own resources within the android environment.

Must I set setContentView() as this: setContentView(QuizSplashActivity.layout.splash) given that I'm trying to call on the layout I made and named as splash.xml within the res/layout folder? . .
 
Ok, I will try my best to explain.

First of all, everything within your /res/ folder is added to R.java: drawables, strings, layouts, etc..

With that said, their types inside of the R.java filer are different depending on their type in /res/ folder. if using resources, setContentView can only use R.layout.* ids. These layout xml files defined in /res/layout sub-directory (and the more specific layout folders, such as /res/layout-land/ , etc...).

Some other methods of various classes accept R.string.* ids, and some, such as Context.findViewById(), accept R.id.* which are a specific View ids found withing the current R.layout.* file specified in setContentView().

I recommend checking out Develop | Android Developers and learning exactly how to program in android before diving in. It's more complex than the JDK.
 
I guess I got a clarification on that part thanks to your statement, the problem however is that whenever I'm trying to call on these custom values in the res folder such as those in colors.xml, strings.xml, etc. an error occurs from the .xml in the layout folder whether R.java is present or not. The error states that: "no resource found that matches the given name".
 
Here's what I'm doing so far. That's only a fraction of the whole application. Kindly point out the wrong parts of the coding that are causing the errors, thanks.
 
Your Layout xml files tried to access resources that didnt exist. The most prominent error was that, you were referencing strings and dimensions as "@strings/blah" and "@dimens/blah". they should be "@string/blah" and "@dimen/blah" (notice the lack of the 's' at the end of string and dimen). Even though your files are named strings.xml and dimens.xml, you still need to reference them using the syntax that the ADT recognizes. Also, when referencing a drawable (i.e. "@drawable/blah"), you need to omit the extension, otherwise the ADT won't be able to find it. For example, if you had a drawable called sprite.png, in one or more of your /res/drawable folders, then you would reference it by "@drawable/sprite", NOT "@drawable/sprite.png".

EDIT: I should also note that if one or more of your resources fail to be "compiled" by the ADT, then the R.java will not be generated. If it doesn't exist, then this is most likely the issue.
 
Ohh, I see. Well thanks a lot for the time you've put into this. Yeah I just noticed you just omitting the letter "s" from the resource xml's under the values folder which got me thinking when it was deliberately have "s" in them, that is, strings.xml, dimens.xml, etc. Now I'm getting that this invoking procedures by ADT got something to do with "keywords" rather than calling specific xml titles.

So here's another noob question: how do we set a textview in Android to show two lines separating a lengthy single strings of text and be able to identify where to split the string at will?

Given this string: "Version 1.0.0 Copyright <some school name> 2012 All Rights Reserved", how will I show it in a textview in 2 lines where the string "Version 1.0.0" stays on the first line while remaining string "Copyright <some school name> 2012 All Rights Reserved" goes on the second line?

I tried using the following android textview attributes:
android:lines="2"
android:maxLines="2"
android:singleLine="false"

But apparently, android doesn't know where to start splitting the lengthy string in two with just these attributes dictating it hence the output still appears as a lengthy single line of string.
 
Make your text view smaller. TextViews do this already, based on their layout_width attribute (unless you explicitly tell it not to). Otherwise, the only way to do it is to manually place a new line character ("\n") somewhere in the string.
 
I found a good way of doing so in complement to the attributes posted above. Given that the resource is a string, to give effect for the \n command, the whole string itself must be enclosed by double-quotations thus gives us this string: "Version 1.0.0 \n Copyright <some school name> 2012 All Rights Reserved".
 
Back
Top Bottom