Developer Newbiew- 2 Questions...


Last Updated:

  1. manurules3

    manurules3 Member This Topic's Starter

    Joined:
    Apr 4, 2010
    Messages:
    12
    Likes Received:
    0
    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 (Text):
    1.  
    2. public class Robot_Invasion extends Activity implements OnClickListener {
    3.    
    4.     public void onClick(View v) {
    5.         switch(v.getId()){
    6.         case R.id.about:
    7.             Intent a = new Intent(this, About.class);
    8.             startActivity (a);
    9.         switch(v.getId()){
    10.         case R.id.help:
    11.             Intent h = new Intent(this, Howtoplay.class);
    12.             startActivity (h);
    13.             break;
    14.         }
    15.         }
    16.    
    17.     }
    18.    
    19.     public void onCreate(Bundle savedInstanceState) {
    20.         super.onCreate(savedInstanceState);
    21.         setContentView(R.layout.main);
    22.    
    23.  
    24.        
    25.         setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    26.    
    27.     View campaignButton = findViewById(R.id.campaign);
    28.     campaignButton.setOnClickListener(this);
    29.     View sandboxButton = findViewById(R.id.sandbox);
    30.     sandboxButton.setOnClickListener(this);
    31.     View howtoplayButton = findViewById(R.id.help);
    32.     howtoplayButton.setOnClickListener(this);
    33.     View aboutButton = findViewById(R.id.about);
    34.     aboutButton.setOnClickListener(this);
    35.    
    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
     

    Advertisement
  2. KlaymenDK

    KlaymenDK Well-Known Member

    Joined:
    May 29, 2009
    Messages:
    1,217
    Likes Received:
    130
    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.
     
    manurules3 likes this.
  3. Schwin97

    Schwin97 Well-Known Member

    Joined:
    Apr 6, 2010
    Messages:
    170
    Likes Received:
    12
    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.
     
    manurules3 likes this.

Share This Page

Loading...