package com.example.layouts;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class LayoutsActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button programmaticButton =
                (Button) findViewById(R.id.programmaticButton);
        programmaticButton
                .setOnClickListener(new ButtonClickListener(
                        HelloProgrammaticActivity.class));
        
        Button xmlButton = (Button) findViewById(R.id.xmlButton);
        xmlButton.setOnClickListener(new ButtonClickListener(
                HelloXMLActivity.class));

        Button linearButton =
                (Button) findViewById(R.id.linearButton);
        linearButton.setOnClickListener(new ButtonClickListener(
                LinearActivity.class));

        Button frameButton = (Button) findViewById(R.id.frameButton);
        frameButton.setOnClickListener(new ButtonClickListener(
                FrameActivity.class));

        Button relativeButton =
                (Button) findViewById(R.id.relativeButton);
        relativeButton.setOnClickListener(new ButtonClickListener(
                RelativeActivity.class));

        Button tableButton = (Button) findViewById(R.id.tableButton);
        tableButton.setOnClickListener(new ButtonClickListener(
                TableActivity.class));

        Button combinedButton =
                (Button) findViewById(R.id.combinedButton);
        combinedButton.setOnClickListener(new ButtonClickListener(
                TemperatureActivity.class));

        Button scrollingButton =
                (Button) findViewById(R.id.scrollingButton);
        scrollingButton.setOnClickListener(new ButtonClickListener(
                AccountRegistrationActivity.class));
    }

    private class ButtonClickListener implements OnClickListener {
        private Class<? extends Activity> destinationClass;

        public ButtonClickListener(Class<? extends Activity> dest) {
            destinationClass = dest;
        }

        public void onClick(View v) {
            Intent i = new Intent();
            i.setClass(LayoutsActivity.this, destinationClass);
            startActivity(i);
        }
    }
}
