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

Apps button in second xml

hi how do i code a button in a second xml so that i can get back to the first xml like from the main screen to the next screen i have that but how and where do i code the button in the second screen so that i can get back to the first screen thanks
 
I cant remember the code as i'm new at it.. but basically, if you know how to do an onlick event from the first button, use the same code, but for the 2nd button, then you can use setContentView(R.layout.xml_name); I *think*.

I'm new at java so I may not be quite correct, maybe post your current code for your first button.
 
ok cool. But where do i put the code for that? does it all go into the same screen where you coded your first xml or do you have to somehow create a new java and link it to the new xml?
 
I think when you create a new xml, the controls on it get an id and that is automatically added to the resource file (R), so you can talk to the button (so to speak) from anywhere in the code as far as I know... when you are using your button1 code on the first layout, are you referencing it using findViewById(R.something_here) ?

Like

Button myButton = (Button)findViewById(R.id.Button01); for example?

My code may be a bit wrong im afraid , but if your button was called 'Button645' and on a different xml layout, I think you can still use it in the same way, so change 01 to 645 and it should pick it up.

As I say, I could be wrong, i've only been looking at it for a week!

P.S, I experimented with this stuff in the main onCreate class.
 
I have tried it several times but it does not seem to work. The app will not load and it force closes. There are no errors in the code though. So I'm confused. It seems like it should work. This is my 119th button and it repeats in more than a hundred screens. So it is a reoccurring button if that makes a difference. Thanks for the help so far.
 
Back
Top Bottom