• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Question about loading Android resources...

purbeast0

No Lifer
Well I'm having an issue here with my Android app and I am not sure how to do this or if it is even possible, and if it isn't, I have to figure something else out.

Now in my /res/drawable folder I have a bunch of .gif files, about 150, which represent icons that are used in my app. Some example files are d.gif, b.gif, db.gif, and dp-p.gif

I also have XML files that store the name of the image that I want to display. It doesn't return the .gif, it will simply return db and dp-p when I parse the XML file.

So for example, I parse an XML file, get a string of dp-p, and I know that is the image that I want to display.

So the way in general I've been calling images to draw is I will have an ImageView and set the icon based on the resource named R.id.<resource name>, and that variable will return an integer ID to the icon, and the draw function knows what to draw based on my ID.

So for instance, to draw the dp-p.gif I would call the image draw function and pass it R.id.dp-p and it would know which image to draw.

The problem I'm having is that since this is dynamically loaded from the value in the XML file, I am not sure how I can just kind of append the R.id. and the value in my XML string in order to pass it into the drawing function, since I'm trying to append an actual string to a variable name.

This is kind of hard for me to explain and I am not sure what to even google search for, but if anyone has any suggestions that would be great, thanks. If you have more questions about my explanation just ask and I will try to explain it better.
 
yea I did omit it, I did it exactly as stated in the tutorial.

what i'm going to try tonight though is see if I can get the resource direcly from my main class in the oncreate function, as soon as the app loads up. i am curious if i can get the ID right then.

i am tryin to access the resource ID when I am 3 listviews down. granted, the initial context is passed into the constructor of the listviews, so i have access to it still at the part i am trying to call this from.

i had other stuff to work on last night and didn't think about at least testing this out at the time to see if it works.

i've found android resource management a PITA in general when compared to iphone development. apple made it really easy to do for the iphone, not nearly as streamlined and simple for the android.
 
yea I did omit it, I did it exactly as stated in the tutorial.

what i'm going to try tonight though is see if I can get the resource direcly from my main class in the oncreate function, as soon as the app loads up. i am curious if i can get the ID right then.

i am tryin to access the resource ID when I am 3 listviews down. granted, the initial context is passed into the constructor of the listviews, so i have access to it still at the part i am trying to call this from.

i had other stuff to work on last night and didn't think about at least testing this out at the time to see if it works.

i've found android resource management a PITA in general when compared to iphone development. apple made it really easy to do for the iphone, not nearly as streamlined and simple for the android.

My Android dev experience is extremely limited (I spent about a week playing around with layouts a few months back), but I do remember the whole R class thing being hard to grasp at first. The entire XML layout thing didn't seem all too useful until I got more used to it either, but soon after I began to appreciate it. I'd like to get back into it some more now that I have some time over the summer so let me know if you keep having problems... I might not have the answer but I'd be willing to look into stuff with you.
 
thanks man, i think i will be getting this issue solved HOPEFULLY tonight, it is like the last thing holding my android port over!

and the XML stuff i'm having issues with is not the resource layout stuff. initially i did have trouble with that as well, but after I started to understand it, you are right, it is pretty nice and powerful.

i know exactly how i can pull my resource if I just do getResourceFromID(R.id.name), but the problem is I am calling it based on a dynamic value that i loaded from another xml file after parsing it.

but i agree the whole R variable was kind of odd at first, but now I'm getting the hang of it.
 
Back
Top