views:

30

answers:

1

Im kinda new on developing for Android, and i've only completed apps like - hello world, paint pot etc.

I know how to design the layout, but when it comes to the "activity" I alwats messes things up..

So now to my question - I'm creating a app to show my school schedule so I have 5 buttons (monday tuesday wednesday etc.) Then when I click each button I want to get to another screen with todays schedule..

How to I create new screens in an easy way? Be kind

+1  A: 

The next time you post something, make sure to include a snippet of code. That way we can easily help you.

With regards to your question... what you have to do is open a new activity from the main activity. That's done by using intents and the startActivity method. I'm gonna give you a simple example where there is only one day (the best day, friday!):

public class SchoolActivity extends Activity{
    public void onCreate(Bundle b){
        super.onCreate(b);
        setContentView(R.layout.shool_layout);

        // you have initialized your buttons here

        // let's suppose this is the reference to your friday button
        btnFriday.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // launch intent for friday
                launchDay(DayDetails.FRIDAY);
            }
        });
    }

    private void launchDay(String whichDay){
        Intent intent = new Intent(SchoolActivity.this, DayDetails.class);
        intent.putExtra(DayDetails.DAY, whichDay);
        startActivity(intent);
    }
}

Then, on your day activity, you will show details for the specified day:

public class DayDetails extends Activity{
    public static final String DAY = "day";
    public static final String FRIDAY = "friday";

    public void onCreate(Bundle b){
        super.onCreate(b);
        setContentView(R.layout.daylayout);

        Bundle extras = getIntent().getExtras();

        if( extras.getString(DAY).equals(FRIDAY) ){
            // show things for the friday
        }
    }
}

Notice that you will have to create two layout files on the res/layout folder; one for the main layout (in this case school_layout.xml) and the other for the day details (daylayout.xml). Hope this example help you and give you an idea of how to proceed in these cases.

Cristian