Author Topic: [Java] What's going wrong?  (Read 2421 times)

0 Members and 1 Guest are viewing this topic.

Offline Ikkerens

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 378
  • Rating: +28/-9
  • JavaScript Magician
    • View Profile
    • Walotech
[Java] What's going wrong?
« on: March 02, 2011, 02:29:08 am »
Well, the Android version of Splut is slowly coming along, if the language would stop being so pricky  :mad:
Anyway, I was wondering if anyone could help me with this,

I have 2 screens (XML format, named gamescreen & main), and at the moment I'm testing it.
Both buttons work, unless I return to the previous screen.
(Basically, I press 1 button to go to gamescreen, works, press the button to go back to the main, works, try to go the gamescreen again, fails.)
Code:
Code: (java) [Select]
package com.walotech.splut;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;

public class Main extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
     //Prepare screen
     //Set landscape orientation
     setRequestedOrientation(0);
     //Remove title bar
     requestWindowFeature(Window.FEATURE_NO_TITLE);
     //Remove taskbar
     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
    
     //Load XML for UI
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        //Assign buttons
        findViewById(R.id.Lev1Start).setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
setContentView(R.layout.gamescreen);
       findViewById(R.id.gbck).setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
setContentView(R.layout.main);
}
       });
}
        });
        findViewById(R.id.makeblue).setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
Button StartButton = (Button) findViewById(R.id.Lev1Start);
StartButton.setBackgroundColor(Color.BLUE);
}
        });
    }
    
    public void AB_main() {
        findViewById(R.id.Lev1Start).setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
setContentView(R.layout.gamescreen);
       AB_gamescreen();
}
        });
        findViewById(R.id.makeblue).setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
Button StartButton = (Button) findViewById(R.id.Lev1Start);
StartButton.setBackgroundColor(Color.BLUE);
}
        });
    }
    
    public void AB_gamescreen() {
     findViewById(R.id.gbck).setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
setContentView(R.layout.main);
AB_main();
}
        });
    }
}


Edit:
Already figured it out, seems I was redefining something that was already given in a function ;)
« Last Edit: March 02, 2011, 11:45:22 am by Ikkerens »

Splut for Android [----------]
Paused/halted indefinitely, might be abandoned, our graphic designer quit and the rest of us simply doesn't have the time to work on it...

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: [Java] What's going wrong?
« Reply #1 on: March 02, 2011, 07:14:31 pm »
Glad you figured it out ^^. I'll leave this intact, though, in case someone has a similar issue later.