views:

31

answers:

1

My app Consists an intro page with "Start", "About", etc..

I managed to create a functional version of the app by having the "Start" button call a new layout in which a new onclick listener is defined.

This doesn't seem clean to me that I@m defining a new onClick listener for each Layout I use and wonder how the correct way would be to create individual pages (including my "About" and any other screens I implement).

Any advice is appreciated, thanks.

A: 

You should create an Activity for each "screen". All the buttons will launch the same event (onClick) and you will start the right activity looking at the ID of the event's source view. Something like this:

public void onButtonClick(View target) {
       System.out.println("Button clicked '" + target + "'");

       switch (target.getId()) {
            case R.id.a_button:
                Intent intent = new Intent(this, AboutActivity.class);
                this.startActivity(intent);
            break;
       }
}
MaxFish
So if I undderstand this right... Start page has an onClick to decide if it launches "Go" or "About" and if "Go" was to be another page each with it's own buttons to activities it would also have another onButton click especially for the buttons and activities related to that one?
Hamid
If your application is like a "tree" that you navigate from the root to the leaves that is generally the way to go, when you'll press back you'll return to the previous activity. But if a screen is simple or is a working mode of an existing activity you may consider to make it a Layout of the Activity that you switch VISIBLE / INVISIBLE.
MaxFish
Say for example, each page was an animated page of a book, although this isn't strictly a "tree" would it still use activities like for example an app that was sharing math equations by topic and branching off into seperate ones?
Hamid