class MainActivity
package com.example.choi.mystudy15;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import com.example.choi.mystudy15.sample2.Sample2Activity;
import com.example.choi.mystudy15.sample3.Sample3Activity;
import com.example.choi.mystudy15.sample4.Sample4Activity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onClick(View v){
Intent intent=null;
switch (v.getId()){
case R.id.button1:
intent=new Intent(this, Sample2Activity.class);
break;
case R.id.button2:
intent=new Intent(this, Sample3Activity.class);
break;
case R.id.button3:
intent=new Intent(this, Sample4Activity.class);
break;
}
startActivity(intent);
}
}
R.layout.activity_main
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.choi.mystudy15.MainActivity">
<Button
android:text="15-2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:id="@+id/button1"
android:background="@android:color/holo_blue_light"
android:onClick="onClick"
/>
<Button
android:text="15-3 (생명주기)"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/button1"
android:layout_centerHorizontal="true"
android:layout_marginTop="36dp"
android:id="@+id/button2"
android:background="@android:color/holo_green_light"
android:onClick="onClick"
/>
<Button
android:text="15-4(화면전환)"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/button2"
android:layout_centerHorizontal="true"
android:layout_marginTop="47dp"
android:id="@+id/button3"
android:background="@android:color/holo_orange_light"
android:onClick="onClick"
/>
</RelativeLayout>
class Sample2Activity
package com.example.choi.mystudy15.sample2;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import com.example.choi.mystudy15.R;
public class Sample2Activity extends AppCompatActivity {
Button bt_01;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sample2);
bt_01=(Button)findViewById(R.id.bt_01);
bt_01.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent =new Intent(Sample2Activity.this, Sample2SecondActivity.class);
startActivity(intent);
}
});
}
}
R.layout.sample2
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/sample2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.choi.mystudy15.sample2.Sample2Activity">
<Button
android:id="@+id/bt_01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10px"
android:text="@string/go_second_activity"
android:layout_marginTop="54dp"
android:background="@android:color/holo_red_light"
android:layout_below="@+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="@android:color/background_light" />
<TextView
android:text="Sample2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:textSize="24sp"
android:textAlignment="center"
android:textStyle="normal|bold"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
class Sample3Activity
package com.example.choi.mystudy15.sample3;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import com.example.choi.mystudy15.R;
public class Sample3Activity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.i("Sample3Activity", "onCreate()");
super.onCreate(savedInstanceState);
setContentView(R.layout.sample3);
}
@Override
protected void onStart() {
Log.i("Sample3Activity", "onStart()");
super.onStart();
}
@Override
protected void onResume() {
Log.i("Sample3Activity", "onResume()");
super.onResume();
}
@Override
protected void onPause() {
Log.i("Sample3Activity", "onPause()");
super.onPause();
}
@Override
protected void onStop() {
Log.i("Sample3Activity", "onStop()");
super.onStop();
}
@Override
protected void onDestroy() {
Log.i("Sample3Activity", "onDestroy()");
super.onDestroy();
}
}
03-05 19:31:10.642 4175-4175/com.example.choi.mystudy15 I/Sample3Activity: onCreate() 03-05 19:31:10.649 4175-4175/com.example.choi.mystudy15 I/Sample3Activity: onStart() 03-05 19:31:10.649 4175-4175/com.example.choi.mystudy15 I/Sample3Activity: onResume() 03-05 19:31:44.226 4175-4175/com.example.choi.mystudy15 I/Sample3Activity: onPause() 03-05 19:31:44.566 4175-4175/com.example.choi.mystudy15 I/Sample3Activity: onStop() 03-05 19:31:44.567 4175-4175/com.example.choi.mystudy15 I/Sample3Activity: onDestroy() |
class Sample4Activity
package com.example.choi.mystudy15.sample4;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import com.example.choi.mystudy15.R;
public class Sample4Activity extends AppCompatActivity {
Button button1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sample4);
button1 =(Button)findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if( getRequestedOrientation()==ActivityInfo.SCREEN_ORIENTATION_PORTRAIT){
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}else{
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/sample4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.choi.mystudy15.sample4.Sample4Activity">
<TextView
android:text="Sample4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:id="@+id/textView3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textSize="24sp"
android:textAlignment="center"
android:textStyle="normal|bold" />
<Button
android:text="화면방향전환"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView3"
android:layout_centerHorizontal="true"
android:layout_marginTop="24dp"
android:id="@+id/button1" />
</RelativeLayout>
댓글 ( 4)
댓글 남기기