Introducing XDA:DevCon – A Conference For Developers By Developers
XDA Developers Android and Mobile Development Forum
Forgot your password?
 
Post Reply+
Tip us?
 
ExO_PoLiTiX
Old
#1  
Member - OP
Thanks Meter 0
Posts: 30
Join Date: Jan 2009
Default Bit of a problem with an app Im making...

Hi,

I am new to android development so sorry if this question has a really obvious answer. I am hoping to make a game for the platform but to start with I have just tried to make a basic layout of 4 buttons to move in different directions and then have a background and an image in front which will be my sprite and move across the screen depending on what button is pressed.

At the moment I have created two views. One via the main xml document and the other through the java code itself. The java code one contains the background and image to be drawn and the main.xml contains the buttons.

At the moment I have my code set up like this:

this.setContentView(R.layout.main); <<<<<<<<<< xml
this.setContentView(this.myTestView); <<<<<<<<<<<<<< java

I am aware that I am basically setting one and then setting the other over the top of it and this means that only one of these views will appear. Does anyone know of a way I can use these views in conjunction so that both the images frm the java file and the layout from the xml can both be used?

Cheers for any help.

ExO
 
barryallott
Old
#2  
Senior Member
Thanks Meter 6
Posts: 282
Join Date: Jul 2009
As far as I know you cannot do this. By calling setContentView you are overwriting the object which held the content previously.

Once the view is set you can add items in code after this call.

Why do you not have all the elements in the xml?
 
ExO_PoLiTiX
Old
#3  
Member - OP
Thanks Meter 0
Posts: 30
Join Date: Jan 2009
aw ok, i wasnt sure if it was possible or not. The reason I did it like this was just because I'm still learning to use both languages. Aswell as that I am using droiddraw to generate my xml and couldnt see an option within that to add images etc. Cheers for the reply .
 
Post Reply+
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Go to top of page...