Android Forums

Go Back   Android Forums > Android Coders > Android Development, Answers, Tutorials, and Code Snippets
Connect with Facebook

Click Here To Register!
Reply
 
LinkBack Thread Tools Display Modes
Old 07-29-2010, 06:28 AM   #11
Android developer
 
Join Date: Jul 2010
Posts: 11
Friends: 0
View chandan's Profile   View chandan's Photo Album   View chandan's Blog   View Social Groups
Hey is it possible to send me the entire class where you are assigning & setting images and xml lines for the ImageView too..I know you can not if the code is too confidential. But I am unable to figure it out where exactly the bug is. :-(
chandan is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati
Reply With Quote
Old 07-29-2010, 07:25 AM   #12
New Member
 
Join Date: Jul 2010
Posts: 6
Friends: 0
View MJLcodee's Profile   View MJLcodee's Photo Album   View MJLcodee's Blog   View Social Groups
Yeah, that line has been set properly.

I googled a bit for that "findViewById returns null", and found stuff like
Quote:
Within findViewById(...) you can only refer to what you set as layout within OnCreate(...)
At any rate that "setContentView(R.layout.whatever)" seems to be important. Thing is, in onCreate, I set: setContentView(R.layout.route_screen);
The image I'm trying to access, however, is in R.layout.route_item.

This is because route_screen is the layout of the overall screen, and route_item is the layout of the objects that get listed inside it.
I mean I can't just replace the layout and make the whole screen look like one item, that's not the idea (and it doesn't work anyway, it makes it crash).

I tested it: findViewById can find all the objects in route_screen, and returns null for all the objects in route_item.

So how can I get around this, to make the findViewById find the right items while keeping the overall layout I want?
MJLcodee is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati
Reply With Quote
Old 07-30-2010, 01:24 AM   #13
Android developer
 
Join Date: Jul 2010
Posts: 11
Friends: 0
View chandan's Profile   View chandan's Photo Album   View chandan's Blog   View Social Groups
Obviously you can not access any views in a layout which are not defined in it.

I assume: you have two xml layout files. depending on some condition in one, you want to set the corresponding image in next layout.(i.e llly, you have two activities where in you are setting respective layout files as its content)

If my assumption is correct then,

Set a variable(must be static ) in the current activity[where you are setting setContentView(R.layout.route_item);] which holds image id to be loaded in to the image view. Then in the activity [where you are setting setContentView(R.layout.route_screen);] set the image view with the value of the (static) variable which was previously set.
chandan is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati
Reply With Quote
Old 07-31-2010, 10:54 AM   #14
New Member
 
Join Date: Jul 2010
Posts: 6
Friends: 0
View MJLcodee's Profile   View MJLcodee's Photo Album   View MJLcodee's Blog   View Social Groups
Thanks for the help, but my friend and I solved it a different way now.

No, see, I had no activity that sets as its content route_item. In the activity whose content is route_screen, I had something similar to a listAdapter that listed all the items (whose layout is route_item). What we did was we wrote a new class that extends ArrayAdapter, which supports changing images.

Thanks.
MJLcodee is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati
Reply With Quote
Reply

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Hard switch Lou Droid Droid X 5 08-18-2010 07:34 PM
What will happen when I switch out my 8gb for 32gb? moxieluv EVO 4G 6 08-01-2010 02:10 AM
Made The Switch.... SkittlezGTI Android Chat 1 06-04-2010 12:51 PM
Need help finding a program nanllyn Android Games And Applications 0 11-10-2009 01:22 PM
How do I switch between and kill apps in memory? dattaway Android Chat 4 07-19-2009 02:37 PM


Unlocked G1 Phones | Buy T-Mobile G1 | Google Phone

All times are GMT -6. The time now is 10:16 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.
Copyright (c) 2008 TalkAndroid.com. All rights reserved.