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

Apps Developer Newbiew- 2 Questions...

Hi, my name is Jamie, and I am an aspiring android app developer. I've read a few tutorials, ebooks, etc. and starting going around developing my first app, which is a game.

First of all, making the main menu for my game, i started to set up the about and how-to-play pages (by creating a separate class for each). Anyway, when in emulation, the about button works, but the how to play button does nothing when clicked. I double checked id's, activity names, and eclipse finds nothing wrong with my code. Here is the code for the activity as it deals to this problem.

Code:
public class Robot_Invasion extends Activity implements OnClickListener {
    
    public void onClick(View v) {
        switch(v.getId()){
        case R.id.about:
            Intent a = new Intent(this, About.class);
            startActivity (a);
        switch(v.getId()){
        case R.id.help:
            Intent h = new Intent(this, Howtoplay.class);
            startActivity (h);
            break;
        }
        }
    
    }
    
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
   

        
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    
    View campaignButton = findViewById(R.id.campaign);
    campaignButton.setOnClickListener(this);
    View sandboxButton = findViewById(R.id.sandbox);
    sandboxButton.setOnClickListener(this);
    View howtoplayButton = findViewById(R.id.help);
    howtoplayButton.setOnClickListener(this);
    View aboutButton = findViewById(R.id.about);
    aboutButton.setOnClickListener(this);
Also, regarding game engine development, has anyone found any good ebooks or tutorials, because I am totally in the dark about that concept, and I am doing all the graphical and layout development before-hand, but I would life to start learning that part.

Thanks in advance,

Jamie
 
Welcome to the forum! :D

Sorry, not much help from me (reading code like that hurts my brain, please use the "#" (code) tag next time.

Also, searching for android game development brings up many interesting results, the one from Robert Green is quite good.
 
I am guessing you have already figured out what is wrong with your code, but if not...

The issue is around the switch statement, and how you have written it to work. As written, you have the code for the help button is actually inside the case for the about button. In order to fix the issue, you will need to add a break statement after "startActivity (a);", and remove the second switch statement (you should only need one switch for all the cases...

Hope that helps.
 
Back
Top Bottom