Omnimaga

General Discussion => Technology and Development => Computer Programming => Topic started by: Ikkerens on March 02, 2011, 02:29:08 am

Title: [Java] What's going wrong?
Post by: Ikkerens 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 ;)
Title: Re: [Java] What's going wrong?
Post by: DJ Omnimaga 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.